From d384ec2540cdde169c0c6961e3a5ba16e80e2628 Mon Sep 17 00:00:00 2001 From: Gareth Kirwan Date: Fri, 23 Aug 2024 09:55:48 +0700 Subject: [PATCH] Subscriptions: Add List.Enabled --- exchanges/subscription/list.go | 11 +++++++++++ exchanges/subscription/list_test.go | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/exchanges/subscription/list.go b/exchanges/subscription/list.go index f250010d6ee..f39272e1591 100644 --- a/exchanges/subscription/list.go +++ b/exchanges/subscription/list.go @@ -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) +} diff --git a/exchanges/subscription/list_test.go b/exchanges/subscription/list_test.go index cd92d171546..b1b43063bb2 100644 --- a/exchanges/subscription/list_test.go +++ b/exchanges/subscription/list_test.go @@ -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") +}