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: fix futures subscription generation #1725

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
15 changes: 8 additions & 7 deletions exchanges/gateio/gateio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2877,13 +2877,14 @@ func TestGenerateDeliveryFuturesDefaultSubscriptions(t *testing.T) {
}
func TestGenerateFuturesDefaultSubscriptions(t *testing.T) {
t.Parallel()
if _, err := g.GenerateFuturesDefaultSubscriptions(currency.USDT); err != nil {
t.Error(err)
}

if _, err := g.GenerateFuturesDefaultSubscriptions(currency.BTC); err != nil {
t.Error(err)
}
subs, err := g.GenerateFuturesDefaultSubscriptions(currency.USDT)
require.NoError(t, err)
require.NotEmpty(t, subs)
subs, err = g.GenerateFuturesDefaultSubscriptions(currency.BTC)
require.NoError(t, err)
require.NotEmpty(t, subs)
_, err = g.GenerateFuturesDefaultSubscriptions(currency.TABOO)
require.Error(t, err)
}
func TestGenerateOptionsDefaultSubscriptions(t *testing.T) {
t.Parallel()
Expand Down
42 changes: 20 additions & 22 deletions exchanges/gateio/gateio_ws_futures.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,41 +103,39 @@ func (g *Gateio) GenerateFuturesDefaultSubscriptions(settlement currency.Code) (
return nil, err
}

var subscriptions subscription.List
for i := range channelsToSubscribe {
switch {
case settlement.Equal(currency.USDT):
pairs, err = pairs.GetPairsByQuote(currency.USDT)
if err != nil {
return nil, err
}
case settlement.Equal(currency.BTC):
offset := 0
for x := range pairs {
if pairs[x].Quote.Equal(currency.USDT) {
continue // skip USDT pairs
}
pairs[offset] = pairs[x]
offset++
settlementPairs := make(currency.Pairs, 0, len(pairs))
gbjk marked this conversation as resolved.
Show resolved Hide resolved
switch {
case settlement.Equal(currency.USDT):
settlementPairs, err = pairs.GetPairsByQuote(currency.USDT)
if err != nil {
gbjk marked this conversation as resolved.
Show resolved Hide resolved
return nil, err
}
case settlement.Equal(currency.BTC):
for x := range pairs {
if pairs[x].Quote.Equal(currency.USDT) {
continue // skip USDT pairs
gbjk marked this conversation as resolved.
Show resolved Hide resolved
gbjk marked this conversation as resolved.
Show resolved Hide resolved
}
pairs = pairs[:offset]
default:
return nil, fmt.Errorf("settlement currency %s not supported", settlement)
settlementPairs = append(settlementPairs, pairs[x])
}
default:
return nil, fmt.Errorf("settlement currency %s not supported", settlement)
}

for j := range pairs {
var subscriptions subscription.List
for i := range channelsToSubscribe {
for j := range settlementPairs {
gbjk marked this conversation as resolved.
Show resolved Hide resolved
params := make(map[string]any)
switch channelsToSubscribe[i] {
case futuresOrderbookChannel:
params["limit"] = 100
params["limit"] = 20
gbjk marked this conversation as resolved.
Show resolved Hide resolved
params["interval"] = "0"
case futuresCandlesticksChannel:
params["interval"] = kline.FiveMin
case futuresOrderbookUpdateChannel:
params["frequency"] = kline.ThousandMilliseconds
params["level"] = "100"
}
fPair, err := g.FormatExchangeCurrency(pairs[j], asset.Futures)
fPair, err := g.FormatExchangeCurrency(settlementPairs[j], asset.Futures)
if err != nil {
return nil, err
}
Expand Down
Loading