Skip to content

Commit

Permalink
bybit: support categorised channel (#1823)
Browse files Browse the repository at this point in the history
* bybit: support categorised channel

Signed-off-by: Ye Sijun <[email protected]>

* remove comment for private func

Co-authored-by: Gareth Kirwan <[email protected]>

---------

Signed-off-by: Ye Sijun <[email protected]>
Co-authored-by: Gareth Kirwan <[email protected]>
  • Loading branch information
junnplus and gbjk authored Mar 6, 2025
1 parent 7fa2592 commit 8f63b0b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
5 changes: 5 additions & 0 deletions exchanges/bybit/bybit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
18 changes: 14 additions & 4 deletions exchanges/bybit/bybit_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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 }}
Expand All @@ -772,6 +781,7 @@ const subTplText = `
{{- end }}
{{- else }}
{{- $name }}
{{- if and (isCategorisedChannel $name) ($categoryName := getCategoryName $asset) -}} . {{- $categoryName -}} {{- end }}
{{- end }}
{{- end }}
{{- $.AssetSeparator }}
Expand Down

0 comments on commit 8f63b0b

Please sign in to comment.