From 8976608f1e6ba38d8ed3c74338285bfedeec8274 Mon Sep 17 00:00:00 2001 From: Gareth Kirwan Date: Thu, 8 Feb 2024 14:46:27 +0700 Subject: [PATCH] Subscriptions: Fix panic on nil Pairs on Matchable keys --- exchanges/kraken/kraken_test.go | 6 +++--- exchanges/kraken/kraken_websocket.go | 2 +- exchanges/subscription/subscription.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/exchanges/kraken/kraken_test.go b/exchanges/kraken/kraken_test.go index bae8b069d38..3b5004d2950 100644 --- a/exchanges/kraken/kraken_test.go +++ b/exchanges/kraken/kraken_test.go @@ -1540,7 +1540,7 @@ func TestWsOHLC(t *testing.T) { k.Websocket.AddSuccessfulSubscriptions(subscription.Subscription{ Key: subscription.Key{ Channel: krakenWsOHLC + "-5", - Pairs: currency.Pairs{btcusdPair}, + Pairs: ¤cy.Pairs{btcusdPair}, Asset: asset.Spot, }, Channel: krakenWsOHLC, @@ -1573,7 +1573,7 @@ func TestWsOrdrbook(t *testing.T) { k.Websocket.AddSuccessfulSubscriptions(subscription.Subscription{ Key: subscription.Key{ Channel: krakenWsOrderbook + "-100", - Pairs: currency.Pairs{btcusdPair}, + Pairs: ¤cy.Pairs{btcusdPair}, Asset: asset.Spot, }, Channel: krakenWsOrderbook, @@ -2006,7 +2006,7 @@ func TestWsOrderbookMax10Depth(t *testing.T) { k.Websocket.AddSuccessfulSubscriptions(subscription.Subscription{ Key: subscription.Key{ Channel: krakenWsOrderbook + "-10", - Pairs: currency.Pairs{p}, + Pairs: ¤cy.Pairs{p}, Asset: asset.Spot, }, Channel: krakenWsOrderbook, diff --git a/exchanges/kraken/kraken_websocket.go b/exchanges/kraken/kraken_websocket.go index 80fc43a964b..e1e345a4863 100644 --- a/exchanges/kraken/kraken_websocket.go +++ b/exchanges/kraken/kraken_websocket.go @@ -186,7 +186,7 @@ func (k *Kraken) wsHandleData(respRaw []byte) error { } } - c := k.Websocket.GetSubscription(subscription.Key{Channel: channelName, Pairs: currency.Pairs{wsPair}, Asset: asset.Spot}) + c := k.Websocket.GetSubscription(subscription.Key{Channel: channelName, Pairs: ¤cy.Pairs{wsPair}, Asset: asset.Spot}) if c == nil { return fmt.Errorf("%w: %s %s %s", stream.ErrSubscriptionNotFound, asset.Spot, channelName, wsPair) } diff --git a/exchanges/subscription/subscription.go b/exchanges/subscription/subscription.go index 68570ac0bfb..66a8f0538c5 100644 --- a/exchanges/subscription/subscription.go +++ b/exchanges/subscription/subscription.go @@ -98,7 +98,7 @@ func (k Key) Match(m Map) *Subscription { if k.Asset != candidate.Asset { continue } - if len(*k.Pairs) == 0 && len(*candidate.Pairs) == 0 { + if (k.Pairs == nil || len(*k.Pairs) == 0) && (candidate.Pairs == nil || len(*candidate.Pairs) == 0) { return v } if err := candidate.Pairs.ContainsAll(*k.Pairs, true); err == nil {