Skip to content

Commit

Permalink
Subscriptions: Add List.Enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Aug 23, 2024
1 parent e372aea commit d384ec2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions exchanges/subscription/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,14 @@ func (l List) assetPairs(e iExchange) (assetPairs, error) {
}
return ap, nil
}

// Enabled returns a new list of only enabled subscriptions
func (l List) Enabled() List {
n := make(List, 0, len(l))
for _, s := range l {
if s.Enabled {
n = append(n, s)
}
}
return slices.Clip(n)
}
9 changes: 9 additions & 0 deletions exchanges/subscription/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,12 @@ func TestListClone(t *testing.T) {
l[0].Interval = kline.OneHour
assert.NotEqual(t, n[0], l[0], "Subscriptions should be cloned")
}

func TestListEnabled(t *testing.T) {
t.Parallel()
l := List{{Channel: TickerChannel}, {Enabled: true, Channel: OrderbookChannel}, {Channel: MyAccountChannel}}
n := l.Enabled()
require.Len(t, l, 3, "Original should not be effected")
require.Len(t, n, 1, "New should be filtered")
require.Equal(t, OrderbookChannel, n[0].Channel, "New should be filtered")
}

0 comments on commit d384ec2

Please sign in to comment.