bybit: support categorised channel (#1823)

* bybit: support categorised channel

Signed-off-by: Ye Sijun <junnplus@gmail.com>

* remove comment for private func

Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>

---------

Signed-off-by: Ye Sijun <junnplus@gmail.com>
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
This commit is contained in:
Jun
2025-03-06 09:15:22 +09:00
committed by GitHub
parent 7fa2592e31
commit 8f63b0b07c
2 changed files with 19 additions and 4 deletions

View File

@@ -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)
}
}

View File

@@ -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 }}