diff --git a/exchanges/stream/websocket.go b/exchanges/stream/websocket.go index ccbca2a92bd..ac29a98a3e5 100644 --- a/exchanges/stream/websocket.go +++ b/exchanges/stream/websocket.go @@ -51,6 +51,7 @@ var ( errSubscriptionNotFound = errors.New("subscription not found in list") errAlreadySubscribed = errors.New("already subscribed") errNoChannelsInArgs = errors.New("no channels in args") + errKeyCannotBeNil = errors.New("key cannot be nil") ) var globalReporter Reporter @@ -973,8 +974,22 @@ func (w *ChannelSubscription) Equal(s *ChannelSubscription) bool { w.Currency.Equal(s.Currency) } -// GetSubscriptions returns a copied list of subscriptions -// and is a private member that cannot be manipulated +// GetSubscription returns a pointer to a copy of the subscription at the key provided +// returns nil if no subscription is at that key or the key is nil +func (w *Websocket) GetSubscription(key any) *ChannelSubscription { + if key == nil || w.subscriptions == nil { + return nil + } + w.subscriptionMutex.RLock() + defer w.subscriptionMutex.RUnlock() + if s, ok := w.subscriptions[key]; ok { + c := s + return &c + } + return nil +} + +// GetSubscriptions returns a new slice of the subscriptions func (w *Websocket) GetSubscriptions() []ChannelSubscription { w.subscriptionMutex.RLock() defer w.subscriptionMutex.RUnlock()