mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Subscriptions: Respect DisableAssetWebsocketSupport for assets (#1693)
* Bitmex: Add index asset to test config * Subscriptions: Fix unsupported WS assets included fixed 1692 * Bitmex: Assertify and fix tests * Subscriptions: Fix all asset subs erroring on no enabled assets Only subs with Empty asset should do anything when assets are empty. If asset is set to all and no assets are enabled, we should return nothing
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -650,16 +650,16 @@ func channelName(s *subscription.Subscription, a asset.Item) string {
|
||||
|
||||
const subTplText = `
|
||||
{{- if $.S.Asset }}
|
||||
{{ range $asset, $pairs := $.AssetPairs }}
|
||||
{{- range $asset, $pairs := $.AssetPairs }}
|
||||
{{- with $name := channelName $.S $asset }}
|
||||
{{- range $i, $p := $pairs -}}
|
||||
{{- $name -}} : {{- $p -}}
|
||||
{{ $.PairSeparator }}
|
||||
{{- range $i, $p := $pairs }}
|
||||
{{- $name -}} : {{- $p }}
|
||||
{{- $.PairSeparator }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{ $.AssetSeparator }}
|
||||
{{- $.AssetSeparator }}
|
||||
{{- end }}
|
||||
{{- else -}}
|
||||
{{ channelName $.S $.S.Asset }}
|
||||
{{- else }}
|
||||
{{- channelName $.S $.S.Asset }}
|
||||
{{- end }}
|
||||
`
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"slices"
|
||||
"strconv"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -2826,8 +2827,9 @@ func TestGenerateSubscriptionsSpot(t *testing.T) {
|
||||
subs, err := g.generateSubscriptionsSpot()
|
||||
require.NoError(t, err, "generateSubscriptions must not error")
|
||||
exp := subscription.List{}
|
||||
assets := slices.DeleteFunc(g.GetAssetTypes(true), func(a asset.Item) bool { return !g.IsAssetWebsocketSupported(a) })
|
||||
for _, s := range g.Features.Subscriptions {
|
||||
for _, a := range g.GetAssetTypes(true) {
|
||||
for _, a := range assets {
|
||||
if s.Asset != asset.All && s.Asset != a {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -31,11 +31,15 @@ func newMockEx() *mockEx {
|
||||
}
|
||||
|
||||
return &mockEx{
|
||||
assets: asset.Items{asset.Spot, asset.Futures},
|
||||
assets: asset.Items{asset.Spot, asset.Futures, asset.Index},
|
||||
pairs: pairs,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *mockEx) IsAssetWebsocketSupported(a asset.Item) bool {
|
||||
return a != asset.Index
|
||||
}
|
||||
|
||||
func (m *mockEx) GetEnabledPairs(_ asset.Item) (currency.Pairs, error) {
|
||||
return m.pairs, m.errPairs
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ type iExchange interface {
|
||||
GetPairFormat(asset.Item, bool) (currency.PairFormat, error)
|
||||
GetSubscriptionTemplate(*Subscription) (*template.Template, error)
|
||||
CanUseAuthenticatedWebsocketEndpoints() bool
|
||||
IsAssetWebsocketSupported(a asset.Item) bool
|
||||
}
|
||||
|
||||
// Strings returns a sorted slice of subscriptions
|
||||
@@ -107,7 +108,12 @@ func fillAssetPairs(ap assetPairs, a asset.Item, e iExchange) error {
|
||||
|
||||
// assetPairs returns a map of enabled pairs for the subscriptions in the list, formatted for the asset
|
||||
func (l List) assetPairs(e iExchange) (assetPairs, error) {
|
||||
at := e.GetAssetTypes(true)
|
||||
at := []asset.Item{}
|
||||
for _, a := range e.GetAssetTypes(true) {
|
||||
if e.IsAssetWebsocketSupported(a) {
|
||||
at = append(at, a)
|
||||
}
|
||||
}
|
||||
ap := assetPairs{}
|
||||
for _, s := range l {
|
||||
switch s.Asset {
|
||||
|
||||
@@ -113,16 +113,19 @@ func expandTemplate(e iExchange, s *Subscription, ap assetPairs, assets asset.It
|
||||
|
||||
switch s.Asset {
|
||||
case asset.All:
|
||||
if len(ap) == 0 {
|
||||
return List{}, nil // No assets enabled; only asset.Empty subs may continue
|
||||
}
|
||||
subCtx.AssetPairs = ap
|
||||
default:
|
||||
if s.Asset != asset.Empty && len(ap[s.Asset]) == 0 {
|
||||
return List{}, nil // No pairs enabled for this sub asset
|
||||
}
|
||||
// This deliberately includes asset.Empty to harmonise handling
|
||||
subCtx.AssetPairs = assetPairs{
|
||||
s.Asset: ap[s.Asset],
|
||||
}
|
||||
assets = asset.Items{s.Asset}
|
||||
if s.Asset != asset.Empty && len(ap[s.Asset]) == 0 {
|
||||
return List{}, nil // Nothing is enabled for this sub asset
|
||||
}
|
||||
}
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
|
||||
@@ -60,9 +60,7 @@ func TestExpandTemplates(t *testing.T) {
|
||||
e.auth = true
|
||||
got, err = l.ExpandTemplates(e)
|
||||
require.NoError(t, err, "ExpandTemplates must not error")
|
||||
exp = append(exp,
|
||||
&Subscription{Channel: "single-channel", QualifiedChannel: "single-channel-authed"},
|
||||
)
|
||||
exp = append(exp, &Subscription{Channel: "single-channel", QualifiedChannel: "single-channel-authed"})
|
||||
equalLists(t, exp, got)
|
||||
|
||||
// Test with just one asset to ensure asset.All works, and disabled assets don't error
|
||||
|
||||
12
testdata/configtest.json
vendored
12
testdata/configtest.json
vendored
@@ -881,6 +881,18 @@
|
||||
"configFormat": {
|
||||
"uppercase": true
|
||||
}
|
||||
},
|
||||
"index": {
|
||||
"assetEnabled": true,
|
||||
"enabled": "-BWBTC",
|
||||
"available": "-BWBTC",
|
||||
"requestFormat": {
|
||||
"uppercase": true
|
||||
},
|
||||
"configFormat": {
|
||||
"uppercase": true,
|
||||
"delimiter": "-"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user