mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-07 07:26:48 +00:00
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:
@@ -94,19 +94,6 @@ func (l List) SetStates(state State) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func fillAssetPairs(ap assetPairs, a asset.Item, e IExchange) error {
|
||||
p, err := e.GetEnabledPairs(a)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
f, err := e.GetPairFormat(a, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ap[a] = common.SortStrings(p.Format(f))
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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 := []asset.Item{}
|
||||
@@ -122,13 +109,13 @@ func (l List) assetPairs(e IExchange) (assetPairs, error) {
|
||||
// Nothing to do
|
||||
case asset.All:
|
||||
for _, a := range at {
|
||||
if err := fillAssetPairs(ap, a, e); err != nil {
|
||||
if err := ap.populate(e, a); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
default:
|
||||
if slices.Contains(at, s.Asset) {
|
||||
if err := fillAssetPairs(ap, s.Asset, e); err != nil {
|
||||
if err := ap.populate(e, s.Asset); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@@ -169,3 +156,17 @@ func (l List) Public() List {
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// populate adds all enabled pairs for an asset to the assetPair map
|
||||
func (ap assetPairs) populate(e IExchange, a asset.Item) error {
|
||||
p, err := e.GetEnabledPairs(a)
|
||||
if err != nil || len(p) == 0 {
|
||||
return err
|
||||
}
|
||||
f, err := e.GetPairFormat(a, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ap[a] = common.SortStrings(p.Format(f))
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user