From 0176ace0efc8f3338cf6ce854b1dd01ec8af58e4 Mon Sep 17 00:00:00 2001 From: Gareth Kirwan Date: Sat, 3 Aug 2024 10:10:47 +0700 Subject: [PATCH] fixup! Bybit: Test Subscriptions --- exchanges/bybit/bybit_test.go | 10 +++++++--- exchanges/bybit/bybit_websocket.go | 13 +++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/exchanges/bybit/bybit_test.go b/exchanges/bybit/bybit_test.go index 731dbf55458..fae0b494b39 100644 --- a/exchanges/bybit/bybit_test.go +++ b/exchanges/bybit/bybit_test.go @@ -3600,20 +3600,24 @@ func TestGenerateSubscriptions(t *testing.T) { } pairs, err := b.GetEnabledPairs(a) require.NoErrorf(t, err, "GetEnabledPairs %s must not error", a) - pairs = common.SortStrings(pairs).Format(currency.PairFormat{Uppercase: true, Delimiter: "_"}) + pairs = common.SortStrings(pairs).Format(currency.PairFormat{Uppercase: true, Delimiter: ""}) s := s.Clone() //nolint:govet // Intentional lexical scope shadow s.Asset = a if isSymbolChannel(channelName(s)) { - for i := range pairs { + for i, p := range pairs { s := s.Clone() //nolint:govet // Intentional lexical scope shadow switch s.Channel { + case subscription.OrderbookChannel: + s.QualifiedChannel = fmt.Sprintf("%s.%d.%s", channelName(s), s.Levels, p) + default: + s.QualifiedChannel = channelName(s) + "." + p.String() } s.Pairs = pairs[i : i+1] exp = append(exp, s) } } else { s.Pairs = pairs - s.QualifiedChannel = pairs.Join() + s.QualifiedChannel = channelName(s) exp = append(exp, s) } } diff --git a/exchanges/bybit/bybit_websocket.go b/exchanges/bybit/bybit_websocket.go index 4c26f1d0655..4c55444b0e9 100644 --- a/exchanges/bybit/bybit_websocket.go +++ b/exchanges/bybit/bybit_websocket.go @@ -57,7 +57,7 @@ const ( var defaultSubscriptions = subscription.List{ {Enabled: true, Asset: asset.Spot, Channel: subscription.TickerChannel}, - {Enabled: true, Asset: asset.Spot, Channel: subscription.OrderbookChannel, Interval: kline.HundredMilliseconds}, + {Enabled: true, Asset: asset.Spot, Channel: subscription.OrderbookChannel, Levels: 50}, {Enabled: true, Asset: asset.Spot, Channel: subscription.AllTradesChannel}, {Enabled: true, Asset: asset.Spot, Authenticated: true, Channel: subscription.MyOrdersChannel}, {Enabled: true, Asset: asset.Spot, Authenticated: true, Channel: subscription.WalletChannel}, @@ -191,7 +191,7 @@ func (by *Bybit) handleSubscriptions(assetType asset.Item, operation string, cha pair := channelsToSubscribe[i].Pairs[0] switch channelsToSubscribe[i].Channel { case chanOrderbook: - arg.Arguments = append(arg.Arguments, fmt.Sprintf("%s.%d.%s", channelsToSubscribe[i].Channel, 50, pair.Format(pairFormat).String())) + arg.Arguments = append(arg.Arguments, fmt.Sprintf("%s.%d.%s", channelsToSubscribe[i].Channel, channelsToSubscribe[i].Levels, pair.Format(pairFormat).String())) case chanPublicTrade, chanPublicTicker, chanLiquidation, chanLeverageTokenTicker, chanLeverageTokenNav: arg.Arguments = append(arg.Arguments, channelsToSubscribe[i].Channel+"."+pair.Format(pairFormat).String()) case chanKline, chanLeverageTokenKline: @@ -271,7 +271,7 @@ func (by *Bybit) GetSubscriptionTemplate(_ *subscription.Subscription) (*templat return template.New("master.tmpl").Funcs(template.FuncMap{ "channelName": channelName, "isSymbolChannel": isSymbolChannel, - "stringToInterval": stringToInterval, + "intervalToString": intervalToString, }).Parse(subTplText) } @@ -797,10 +797,11 @@ const subTplText = ` {{- range $asset, $pairs := $.AssetPairs }} {{- if isSymbolChannel $name }} {{- range $p := $pairs }} - {{- $name }} - {{- if eq $name "orderbook" -}} . {{- $.S.Levels }}{{ end }} - {{- if eq $name "kline" -}} . {{- intervalToString $.S.Interval }}{{ end }} + {{- $name -}} . + {{- if eq $name "orderbook" -}} {{- $.S.Levels -}} . {{- end }} + {{- if eq $name "kline" -}} {{- intervalToString $.S.Interval -}} . {{- end }} {{- $p }} + {{- $.PairSeparator }} {{- end }} {{- else }} {{- $name }}