From 8f63b0b07c7bb13309d3c55d262612252a6069ef Mon Sep 17 00:00:00 2001 From: Jun Date: Thu, 6 Mar 2025 09:15:22 +0900 Subject: [PATCH] bybit: support categorised channel (#1823) * bybit: support categorised channel Signed-off-by: Ye Sijun * remove comment for private func Co-authored-by: Gareth Kirwan --------- Signed-off-by: Ye Sijun Co-authored-by: Gareth Kirwan --- exchanges/bybit/bybit_test.go | 5 +++++ exchanges/bybit/bybit_websocket.go | 18 ++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/exchanges/bybit/bybit_test.go b/exchanges/bybit/bybit_test.go index caeea790..18027507 100644 --- a/exchanges/bybit/bybit_test.go +++ b/exchanges/bybit/bybit_test.go @@ -3736,6 +3736,11 @@ func TestGenerateSubscriptions(t *testing.T) { } else { s.Pairs = pairs s.QualifiedChannel = channelName(s) + categoryName := getCategoryName(a) + if isCategorisedChannel(s.QualifiedChannel) && categoryName != "" { + s.QualifiedChannel += "." + categoryName + } + exp = append(exp, s) } } diff --git a/exchanges/bybit/bybit_websocket.go b/exchanges/bybit/bybit_websocket.go index 59803308..63a29fad 100644 --- a/exchanges/bybit/bybit_websocket.go +++ b/exchanges/bybit/bybit_websocket.go @@ -65,7 +65,6 @@ var defaultSubscriptions = subscription.List{ {Enabled: true, Asset: asset.Spot, Authenticated: true, Channel: subscription.MyOrdersChannel}, {Enabled: true, Asset: asset.Spot, Authenticated: true, Channel: subscription.MyWalletChannel}, {Enabled: true, Asset: asset.Spot, Authenticated: true, Channel: subscription.MyTradesChannel}, - {Enabled: true, Asset: asset.Spot, Authenticated: true, Channel: chanPositions}, } var subscriptionNames = map[string]string{ @@ -242,9 +241,11 @@ func (by *Bybit) generateSubscriptions() (subscription.List, error) { // GetSubscriptionTemplate returns a subscription channel template func (by *Bybit) GetSubscriptionTemplate(_ *subscription.Subscription) (*template.Template, error) { return template.New("master.tmpl").Funcs(template.FuncMap{ - "channelName": channelName, - "isSymbolChannel": isSymbolChannel, - "intervalToString": intervalToString, + "channelName": channelName, + "isSymbolChannel": isSymbolChannel, + "intervalToString": intervalToString, + "getCategoryName": getCategoryName, + "isCategorisedChannel": isCategorisedChannel, }).Parse(subTplText) } @@ -759,6 +760,14 @@ func isSymbolChannel(name string) bool { return true } +func isCategorisedChannel(name string) bool { + switch name { + case chanPositions, chanExecution, chanOrder: + return true + } + return false +} + const subTplText = ` {{ with $name := channelName $.S }} {{- range $asset, $pairs := $.AssetPairs }} @@ -772,6 +781,7 @@ const subTplText = ` {{- end }} {{- else }} {{- $name }} + {{- if and (isCategorisedChannel $name) ($categoryName := getCategoryName $asset) -}} . {{- $categoryName -}} {{- end }} {{- end }} {{- end }} {{- $.AssetSeparator }}