Subscriptions: Fix no enabled pairs for one asset (#1792)

If one asset is enabled but has no enabled pairs, we should ignore that
asset, even for non-pair related subscriptions.
That matches the existing code, but wasn't happening in the context of
asset.All subscriptions with just one asset in this state.
If a user wanted to have non-pair subscriptions, they should use
asset.Empty. Would expect other breakages with no pairs enabled, too.

Note: No enabled pairs for an enabled asset is a transient issue which
can occur due to enableOnePair racing against no available pairs. The
second run, available pairs would be populated and enableOnePair would
work. This situation could persist due to running with --dry or
containerised, though.

Fixes:
`
Okx websocket: subscription failure, myOrders all : subscription template did not generate the expected number of pair records for spread: Got 1;
Expected 0
`

Relates to #1420
This commit is contained in:
Gareth Kirwan
2025-03-06 01:08:08 +00:00
committed by GitHub
parent 0796e44063
commit d069ff2bf4
6 changed files with 84 additions and 44 deletions

View File

@@ -114,6 +114,31 @@ func TestAssetPairs(t *testing.T) {
}
}
// TestAssetPairsPopulate exercises assetPairs Populate
func TestAssetPairsPopulate(t *testing.T) {
e := newMockEx()
ap := assetPairs{}
err := ap.populate(e, asset.Spot)
require.NoError(t, err)
require.NotEmpty(t, ap)
assert.Equal(t, 3, len(ap[asset.Spot]), "populate should return correct number of pairs for spot")
assert.Equal(t, "BTC-USDT", ap[asset.Spot][0].String(), "populate should respect format and sort the pairs")
err = ap.populate(e, asset.Futures)
require.NoError(t, err)
assert.Equal(t, 2, len(ap[asset.Futures]), "populate should return correct number of pairs for futures")
exp := errors.New("expected error")
e.errFormat = exp
err = ap.populate(e, asset.Spot)
assert.ErrorIs(t, err, exp, "populate should error correctly on format error")
e.pairs = assetPairs{}
ap = assetPairs{}
err = ap.populate(e, asset.Spot)
require.NoError(t, err, "populate must not error with no pairs enabled")
assert.Empty(t, ap, "populate should return an empty map with no pairs enabled")
}
func TestListClone(t *testing.T) {
t.Parallel()
l := List{{Channel: TickerChannel}, {Channel: OrderbookChannel}}