Skip to content

Commit

Permalink
Bitfinex: chanForSub return only first match
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Sep 14, 2023
1 parent 2c356b7 commit 22ffbf5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 20 deletions.
6 changes: 0 additions & 6 deletions exchanges/bitfinex/bitfinex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1871,10 +1871,4 @@ func TestChanForSub(t *testing.T) {
s, err = b.chanForSub(wsBook, asset.Spot, p)
assert.Nil(t, err, "No error returned when sub found")
assert.EqualValues(t, want, *s, "Correct Sub found")

dup := stream.ChannelSubscription{Asset: asset.Spot, Currency: p, Channel: wsBook, Params: map[string]interface{}{"muffins": "yummy"}}
b.Websocket.AddSuccessfulSubscriptions(dup)
s, err = b.chanForSub(wsBook, asset.Spot, p)
assert.ErrorIs(t, err, errTooManyMatchingSubs, "Correct error returns when too many subs found")
assert.Nil(t, s, "No stream returned when too many subs found")
}
7 changes: 3 additions & 4 deletions exchanges/bitfinex/bitfinex_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import (
)

var (
errSetCannotBeEmpty = errors.New("set cannot be empty")
errSubNotFound = errors.New("could not find matching subscription")
errTooManyMatchingSubs = errors.New("too many matching subscriptions")
errTypeAssert = errors.New("type assertion failed")
errSetCannotBeEmpty = errors.New("set cannot be empty")
errSubNotFound = errors.New("could not find matching subscription")
errTypeAssert = errors.New("type assertion failed")
)

// AccountV2Data stores account v2 data
Expand Down
12 changes: 2 additions & 10 deletions exchanges/bitfinex/bitfinex_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,6 @@ func (b *Bitfinex) resubOrderbook(p currency.Pair, assetType asset.Item) error {

// chanForSub returns an existing channel subscription for a given channel/asset/pair
func (b *Bitfinex) chanForSub(cName string, assetType asset.Item, pair currency.Pair) (*stream.ChannelSubscription, error) {
var c *stream.ChannelSubscription
want := &stream.ChannelSubscription{
Channel: cName,
Currency: pair,
Expand All @@ -1562,17 +1561,10 @@ func (b *Bitfinex) chanForSub(cName string, assetType asset.Item, pair currency.
subs := b.Websocket.GetSubscriptions()
for i := range subs {
if subs[i].Equal(want) {
if c != nil {
return nil, errTooManyMatchingSubs
}
c = &subs[i]
return &subs[i], nil
}
}
if c == nil {
return nil, errSubNotFound
}

return c, nil
return nil, errSubNotFound
}

// GenerateDefaultSubscriptions Adds default subscriptions to websocket to be handled by ManageSubscriptions()
Expand Down

0 comments on commit 22ffbf5

Please sign in to comment.