Skip to content

Commit

Permalink
Subscriptions: Fix panic on nil Pairs on Matchable keys
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Feb 8, 2024
1 parent 18edb4f commit 8976608
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions exchanges/kraken/kraken_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: &currency.Pairs{btcusdPair},
Asset: asset.Spot,
},
Channel: krakenWsOHLC,
Expand Down Expand Up @@ -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: &currency.Pairs{btcusdPair},
Asset: asset.Spot,
},
Channel: krakenWsOrderbook,
Expand Down Expand Up @@ -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: &currency.Pairs{p},
Asset: asset.Spot,
},
Channel: krakenWsOrderbook,
Expand Down
2 changes: 1 addition & 1 deletion exchanges/kraken/kraken_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: &currency.Pairs{wsPair}, Asset: asset.Spot})
if c == nil {
return fmt.Errorf("%w: %s %s %s", stream.ErrSubscriptionNotFound, asset.Spot, channelName, wsPair)
}
Expand Down
2 changes: 1 addition & 1 deletion exchanges/subscription/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8976608

Please sign in to comment.