Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gateio: Add websocket request functions for futures trading (btc and usdt margined) #1603

Open
wants to merge 186 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
186 commits
Select commit Hold shift + click to select a range
64c24ab
gateio: Add multi asset websocket support WIP.
Jul 14, 2024
f509399
meow
Jul 14, 2024
feed04e
Add tests and shenanigans
Jul 15, 2024
31a26c0
integrate flushing and for enabling/disabling pairs from rpc shenanigans
Jul 15, 2024
e1f2f7a
some changes
Jul 15, 2024
76524cc
linter: fixes strikes again.
Jul 15, 2024
640e82e
Change name ConnectionAssociation -> ConnectionCandidate for better c…
Jul 15, 2024
3a0440d
Add subscription tests (state functional)
Jul 16, 2024
c7d2b62
glorious:nits + proxy handling
Jul 16, 2024
fc281ee
Spelling
Jul 16, 2024
eaa44ba
linter: fixerino
Jul 16, 2024
a8debf9
instead of nil, dont do nil.
Jul 16, 2024
16b0e22
clean up nils
Jul 16, 2024
32252b2
cya nils
Jul 16, 2024
7c5d9c3
don't need to set URL or check if its running
Jul 17, 2024
2f93b64
stream match update
Jul 17, 2024
dd94e4e
update tests
Jul 17, 2024
ca597f3
linter: fix
Jul 17, 2024
2e0f0ae
glorious: nits + handle context cancellations
Jul 18, 2024
2d2f872
stop ping handler routine leak
Jul 19, 2024
39191c8
* Fix bug where reader routine on error that is not a disconnection e…
Jul 19, 2024
f1c3895
Allow rollback on connect on any error across all connections
Jul 19, 2024
09bff6c
fix shadow jutsu
Jul 19, 2024
e66c9be
glorious/gk: nitters - adds in ws mock server
Jul 22, 2024
03de669
linter: fix
Jul 22, 2024
eddb58b
Merge branch 'master' into gateio_ws
Jul 23, 2024
8159b05
fix deadlock on connection as the previous channel had no reader and …
Jul 24, 2024
4f0b42f
Merge branch 'master' into gateio_ws
Jul 24, 2024
2af934e
Merge branch 'master' into stream_match
Jul 24, 2024
0e3bb31
glorious: whooops
Jul 24, 2024
f98c3aa
gk: nits
Jul 24, 2024
d89a46a
Leak issue and edge case
Jul 25, 2024
8281b88
Websocket: Add SendMessageReturnResponses
gbjk Apr 8, 2024
a38a1d1
whooooooopsie
Jul 25, 2024
77ef366
gk: nitssssss
Jul 26, 2024
6341ccf
Update exchanges/stream/stream_match.go
shazbert Jul 26, 2024
c0d1d43
Update exchanges/stream/stream_match_test.go
shazbert Jul 26, 2024
9e57e65
linter: appease the linter gods
Jul 26, 2024
51b9f17
gk: nits
Jul 26, 2024
6376a12
gk: drain brain
Jul 26, 2024
f7adad2
started
Jul 28, 2024
9905686
more changes before merge match pr
Jul 31, 2024
d275e39
Merge branch 'master' into stream_match
Jul 31, 2024
8a64da1
Merge branch 'stream_match' into ws_outbound_req
Jul 31, 2024
9bb6ef4
gateio: still building out
Jul 31, 2024
3f3da46
gateio: finish spot
Jul 31, 2024
6b9c4ad
fix up tests in gateio
Jul 31, 2024
f7af44c
Add tests for stream package
Jul 31, 2024
3ed912b
rm unused field
Jul 31, 2024
ee8a35c
glorious: nits
Aug 1, 2024
ec33bd3
Merge branch 'stream_match' into ws_outbound_req
Aug 1, 2024
cc97528
rn files, specifically set function names to asset and offload routin…
Aug 3, 2024
66a8778
linter: fix
Aug 6, 2024
f7ae6b0
Add futures websocket request support
Aug 6, 2024
4d5d681
gateio: integrate with IBOTExchange (cherry pick my nose)
Aug 7, 2024
3969969
linter: fix
Aug 7, 2024
431c047
glorious: nits
Aug 15, 2024
7110e88
add counter and update gateio
Aug 16, 2024
67bb87d
Merge branch 'common_counter' into ws_outbound_req
Aug 16, 2024
b70296c
fix collision issue
Aug 16, 2024
aa3b49f
Merge branch 'ws_outbound_req' into ws_oubtound_req_futures
Aug 16, 2024
d5bbd10
Merge branch 'master' into gateio_ws
Aug 19, 2024
d2f7c2e
Merge branch 'master' into gateio_ws
Aug 23, 2024
16d88cf
Merge branch 'master' into gateio_ws
Aug 24, 2024
9026bc8
Merge branch 'gateio_ws' into ws_outbound_req
Aug 24, 2024
9e860cf
Merge branch 'ws_outbound_req' into ws_oubtound_req_futures
Aug 24, 2024
0402bc7
Update exchanges/stream/websocket.go
shazbert Aug 30, 2024
0dfda95
glorious: nits
Aug 30, 2024
c58834e
add tests
Aug 30, 2024
d29893b
linter: fix
Aug 30, 2024
79e0eeb
Merge branch 'master' into gateio_ws
Aug 30, 2024
4f7bcd9
Merge branch 'master' into gateio_ws
Sep 2, 2024
45ff199
After merge
Sep 2, 2024
06acaac
Add error connection info
Sep 2, 2024
aa87e83
Merge branch 'gateio_ws' into ws_outbound_req
Sep 4, 2024
cf2e8d8
upgrade to upstream merge
Sep 5, 2024
e9d50e4
Merge branch 'ws_outbound_req' into ws_oubtound_req_futures
Sep 5, 2024
af986da
Fix edge case where it does not reconnect made by an already closed c…
Sep 9, 2024
1171278
stream coverage
Sep 12, 2024
4be6214
glorious: nits
Sep 12, 2024
a068ddb
Merge branch 'master' into gateio_ws
Sep 12, 2024
81cba36
glorious: nits removed asset error handling in stream package
Sep 12, 2024
bdc6954
linter: fix
Sep 13, 2024
3fe44ca
rm block
Sep 13, 2024
818584f
Add basic readme
Sep 13, 2024
289ac71
Merge branch 'master' into gateio_ws
Sep 13, 2024
dee32a4
Merge branch 'master' into gateio_ws
Sep 13, 2024
7063311
Merge branch 'master' into gateio_ws
Sep 16, 2024
0709ba3
fix asset enabled flush cycle for multi connection
Sep 16, 2024
b877b38
spella: fix
Sep 16, 2024
f7d1ec8
linter: fix
Sep 18, 2024
818432d
Merge branch 'master' into gateio_ws
Sep 18, 2024
bdc7afb
Add glorious suggestions, fix some race thing
Sep 19, 2024
3d6541e
reinstate name before any routine gets spawned
Sep 19, 2024
33c4128
stop on error in mock tests
Sep 19, 2024
ea25763
glorious: nits
Sep 19, 2024
f15374a
Merge branch 'gateio_ws' into ws_outbound_req
Sep 22, 2024
ce00326
Merge branch 'ws_outbound_req' into ws_oubtound_req_futures
Sep 22, 2024
262c6ef
Set correct price
Sep 22, 2024
ae92cd2
glorious: nits found in CI build
Sep 24, 2024
c49a75c
Add test for drain, bumped wait times as there seems to be something …
Sep 24, 2024
5551d54
mutex across shutdown and connect for protection
Sep 24, 2024
99c3c7b
lint: fix
Sep 24, 2024
f56cb78
test time withoffset, reinstate stop
Sep 24, 2024
b4bc7e2
fix whoops
Sep 24, 2024
ce4a5ce
const trafficCheckInterval; rm testmain
Sep 24, 2024
a745992
y
Sep 24, 2024
086fcc3
fix lint
Sep 24, 2024
a64e842
bump time check window
Sep 24, 2024
9e53313
stream: fix intermittant test failures while testing routines and rem…
Sep 25, 2024
10230b0
spells
Sep 25, 2024
4e02c4a
cant do what I did
Sep 25, 2024
7be80a0
protect race due to routine.
Sep 25, 2024
b51cf2f
update testURL
Sep 25, 2024
ff7ae03
use mock websocket connection instead of test URL's
Sep 25, 2024
1040153
linter: fix
Sep 25, 2024
f529bd2
remove url because its throwing errors on CI builds
Sep 25, 2024
5d0a7f7
connections drop all the time, don't need to worry about not being ab…
Sep 25, 2024
56cb431
remove another superfluous url thats not really set up for this
Sep 25, 2024
ca4999e
spawn overwatch routine when there is no errors, inline checker inste…
Sep 25, 2024
4240a0a
linter: fixerino uperino
Sep 26, 2024
c3a5bab
fix ID bug, why I do this, I don't know.
Sep 26, 2024
8d6febc
glorious: panix
Sep 30, 2024
3df82ef
Merge branch 'master' into gateio_ws
Oct 1, 2024
7ff07d1
Merge branch 'master' into gateio_ws
Oct 1, 2024
3a24640
linter: things
Oct 1, 2024
1eef208
whoops
Oct 1, 2024
261b577
Merge branch 'master' into gateio_ws
Oct 1, 2024
dbd8acd
Merge branch 'gateio_ws' into ws_outbound_req
Oct 2, 2024
b528407
dont need to make consecutive Unix() calls
Oct 2, 2024
0c5dbbf
Merge branch 'ws_outbound_req' into ws_oubtound_req_futures
Oct 2, 2024
ee1cb94
websocket: fix potential panic on error and no responses and adding w…
Oct 3, 2024
6e46e74
Merge branch 'ws_outbound_req' into ws_oubtound_req_futures
Oct 3, 2024
9cdac76
Merge branch 'master' into ws_outbound_req
Oct 10, 2024
e5accaf
rm json parser and handle in json package instead
Oct 10, 2024
30ed109
Merge branch 'ws_outbound_req' into ws_oubtound_req_futures
Oct 10, 2024
20d7737
in favour of json package unmarshalling
Oct 10, 2024
f124390
Merge branch 'master' into ws_outbound_req
Oct 23, 2024
d950b24
linter: fix
Oct 23, 2024
31339ed
linter: fix again
Oct 23, 2024
622c748
* change field name OutboundRequestSignature to WrapperDefinedConnect…
Oct 23, 2024
b71d3c0
spells and magic and wands
Oct 23, 2024
c7d8503
Merge branch 'ws_outbound_req' into ws_oubtound_req_futures
Oct 23, 2024
2bd207f
glorious: nits
Oct 25, 2024
511c78b
comparable check for signature
Oct 25, 2024
0a196b8
mv err var
Oct 25, 2024
f5ffe9f
Merge branch 'master' into ws_outbound_req
Nov 5, 2024
d3343a7
glorious: nits and stuff
Nov 5, 2024
800665c
Merge branch 'ws_outbound_req' into ws_oubtound_req_futures
Nov 5, 2024
56f483f
Merge branch 'master' into ws_outbound_req
Nov 7, 2024
2872e05
attempt to fix race
Nov 7, 2024
50e7253
Merge branch 'master' into ws_outbound_req
Nov 11, 2024
fae9556
Merge branch 'ws_outbound_req' into ws_oubtound_req_futures
Nov 11, 2024
2b79a9c
glorious: nits
Nov 15, 2024
1696d08
gk: nits; engine log cleanup
Nov 20, 2024
cb2a235
gk: nits; OCD
Nov 20, 2024
78e974a
gk: nits; move function change file names
Nov 20, 2024
00a267d
gk: nits; :rocket:
Nov 20, 2024
72f97dd
gk: nits; convert variadic function and message inspection to interfa…
Nov 20, 2024
274ae8f
gk: nits; continued
Nov 20, 2024
25f00ce
gk: engine nits; rm loaded exchange
Nov 22, 2024
058b184
gk: nits; drop WebsocketLoginResponse
Nov 22, 2024
a87c438
stream: Add match method EnsureMatchWithData
Nov 22, 2024
6a2fbde
gk: nits; rn Inspect to IsFinal
Nov 22, 2024
cb96521
gk: nits; rn to MessageFilter
Nov 22, 2024
3417a55
linter: fix
Nov 23, 2024
03d9045
Merge branch 'master' into ws_outbound_req
Nov 26, 2024
70781cb
gateio: update rate limit definitions (cherry-pick)
Nov 27, 2024
6803a2a
Add test and missing
Nov 27, 2024
f8729d2
Merge branch 'master' into gateio_rate_limits
Dec 5, 2024
4baa7a2
Shared REST rate limit definitions with Websocket service, set lookup…
Dec 5, 2024
c0f0cd4
Merge branch 'master' into gateio_rate_limits
Dec 9, 2024
ede517b
Merge branch 'gateio_rate_limits' into ws_outbound_req
Dec 9, 2024
9c56cbb
integrate rate limits for websocket trading spot
Dec 9, 2024
8f0fd7f
Merge branch 'ws_outbound_req' into ws_oubtound_req_futures
Dec 9, 2024
4dbd56d
Merge branch 'master' into ws_oubtound_req_futures
Dec 22, 2024
ec03c5d
conform to match upstream changes
Dec 22, 2024
5f464e0
standardise names to upstream style
Dec 22, 2024
ef25647
fix wrapper standards test when sending a auth request through a webs…
Dec 22, 2024
eb8173b
whoops
Dec 22, 2024
42314cd
Update exchanges/gateio/gateio_types.go
shazbert Dec 31, 2024
8914c40
Merge branch 'master' into ws_oubtound_req_futures
Jan 1, 2025
0338930
glorious: nits
Jan 2, 2025
96f579e
linter: fix
Jan 2, 2025
59ca444
linter: overload
Jan 2, 2025
2f322e2
whoops
Jan 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/exchanges/margin"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
"github.com/thrasher-corp/gocryptotrader/exchanges/stream"
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
)
Expand Down Expand Up @@ -641,6 +642,7 @@ var acceptableErrors = []error{
order.ErrCannotValidateAsset, // Is thrown when attempting to get order limits from an asset that is not yet loaded
order.ErrCannotValidateBaseCurrency, // Is thrown when attempting to get order limits from an base currency that is not yet loaded
order.ErrCannotValidateQuoteCurrency, // Is thrown when attempting to get order limits from an quote currency that is not yet loaded
stream.ErrNotConnected, // Is thrown when attempting to send a message to a websocket that is not connected
}

// warningErrors will t.Log(err) when thrown to diagnose things, but not necessarily suggest
Expand Down
5 changes: 5 additions & 0 deletions exchanges/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -1943,3 +1943,8 @@ func (b *Base) GetTradingRequirements() protocol.TradingRequirements {
}
return b.Features.TradingRequirements
}

// WebsocketSubmitOrder submits an order to the exchange via a websocket connection
func (*Base) WebsocketSubmitOrder(context.Context, *order.Submit) (*order.SubmitResponse, error) {
return nil, common.ErrFunctionNotSupported
}
5 changes: 5 additions & 0 deletions exchanges/exchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3076,3 +3076,8 @@ func TestGetTradingRequirements(t *testing.T) {
requirements = (&Base{Features: Features{TradingRequirements: protocol.TradingRequirements{ClientOrderID: true}}}).GetTradingRequirements()
require.NotEmpty(t, requirements)
}

func TestWebsocketSubmitOrder(t *testing.T) {
_, err := (&Base{}).WebsocketSubmitOrder(context.Background(), nil)
require.ErrorIs(t, err, common.ErrFunctionNotSupported)
}
10 changes: 5 additions & 5 deletions exchanges/gateio/gateio.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ func (g *Gateio) GetUnifiedAccount(ctx context.Context, ccy currency.Code) (*Uni

// CreateBatchOrders Create a batch of orders Batch orders requirements: custom order field text is required At most 4 currency pairs,
// maximum 10 orders each, are allowed in one request No mixture of spot orders and margin orders, i.e. account must be identical for all orders
func (g *Gateio) CreateBatchOrders(ctx context.Context, args []CreateOrderRequestData) ([]SpotOrder, error) {
func (g *Gateio) CreateBatchOrders(ctx context.Context, args []CreateOrderRequest) ([]SpotOrder, error) {
if len(args) > 10 {
return nil, fmt.Errorf("%w only 10 orders are canceled at once", errMultipleOrders)
}
Expand Down Expand Up @@ -633,7 +633,7 @@ func (g *Gateio) SpotClosePositionWhenCrossCurrencyDisabled(ctx context.Context,

// PlaceSpotOrder creates a spot order you can place orders with spot, margin or cross margin account through setting the accountfield.
// It defaults to spot, which means spot account is used to place orders.
func (g *Gateio) PlaceSpotOrder(ctx context.Context, arg *CreateOrderRequestData) (*SpotOrder, error) {
func (g *Gateio) PlaceSpotOrder(ctx context.Context, arg *CreateOrderRequest) (*SpotOrder, error) {
if arg == nil {
return nil, errNilArgument
}
Expand Down Expand Up @@ -2264,7 +2264,7 @@ func (g *Gateio) UpdatePositionRiskLimitInDualMode(ctx context.Context, settle c
// Set reduce_only to true can keep the position from changing side when reducing position size
// In single position mode, to close a position, you need to set size to 0 and close to true
// In dual position mode, to close one side position, you need to set auto_size side, reduce_only to true and size to 0
func (g *Gateio) PlaceFuturesOrder(ctx context.Context, arg *OrderCreateParams) (*Order, error) {
func (g *Gateio) PlaceFuturesOrder(ctx context.Context, arg *ContractOrderCreateParams) (*Order, error) {
if arg == nil {
return nil, errNilArgument
}
Expand Down Expand Up @@ -2352,7 +2352,7 @@ func (g *Gateio) CancelMultipleFuturesOpenOrders(ctx context.Context, contract c
// In the returned result, the succeeded field of type bool indicates whether the execution was successful or not
// If the execution is successful, the normal order content is included; if the execution fails, the label field is included to indicate the cause of the error
// In the rate limiting, each order is counted individually
func (g *Gateio) PlaceBatchFuturesOrders(ctx context.Context, settle currency.Code, args []OrderCreateParams) ([]Order, error) {
func (g *Gateio) PlaceBatchFuturesOrders(ctx context.Context, settle currency.Code, args []ContractOrderCreateParams) ([]Order, error) {
if settle.IsEmpty() {
return nil, errEmptyOrInvalidSettlementCurrency
}
Expand Down Expand Up @@ -2840,7 +2840,7 @@ func (g *Gateio) UpdateDeliveryPositionRiskLimit(ctx context.Context, settle cur

// PlaceDeliveryOrder create a futures order
// Zero-filled order cannot be retrieved 10 minutes after order cancellation
func (g *Gateio) PlaceDeliveryOrder(ctx context.Context, arg *OrderCreateParams) (*Order, error) {
func (g *Gateio) PlaceDeliveryOrder(ctx context.Context, arg *ContractOrderCreateParams) (*Order, error) {
if arg == nil {
return nil, errNilArgument
}
Expand Down
Loading
Loading