From fdac3362c1d47d19d32afca11d687744b6e0284b Mon Sep 17 00:00:00 2001 From: Gareth Kirwan Date: Fri, 3 Nov 2023 13:25:57 +0800 Subject: [PATCH] Swich to external package for channel subscriptions --- config/config_types.go | 3 ++- exchanges/exchange.go | 22 +++++----------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/config/config_types.go b/config/config_types.go index fe73c1e5a1c..91aeb5484b2 100644 --- a/config/config_types.go +++ b/config/config_types.go @@ -10,6 +10,7 @@ import ( "github.com/thrasher-corp/gocryptotrader/database" "github.com/thrasher-corp/gocryptotrader/exchanges/kline" "github.com/thrasher-corp/gocryptotrader/exchanges/protocol" + "github.com/thrasher-corp/gocryptotrader/exchanges/subscription" gctscript "github.com/thrasher-corp/gocryptotrader/gctscript/vm" "github.com/thrasher-corp/gocryptotrader/log" "github.com/thrasher-corp/gocryptotrader/portfolio" @@ -311,7 +312,7 @@ type FeaturesEnabledConfig struct { SaveTradeData bool `json:"saveTradeData"` TradeFeed bool `json:"tradeFeed"` FillsFeed bool `json:"fillsFeed"` - Subscriptions []EnabledSubscriptionConfig `json:"subscriptions,omitempty"` + Subscriptions []subscription.Subscription `json:"subscriptions,omitempty"` } type EnabledSubscriptionConfig struct { diff --git a/exchanges/exchange.go b/exchanges/exchange.go index 374e457a9f4..c948978efbe 100644 --- a/exchanges/exchange.go +++ b/exchanges/exchange.go @@ -165,29 +165,17 @@ func (b *Base) SetFeatureDefaults() { // If the subscriptions config is empty then Config will be updated from the exchange subs, // allowing e.SetDefaults to set default subscriptions for an exchange to update user's config // Note: It's not possible to configure no subscriptions for a websocket -// TODO: Abstract the Marshal/Unmarshal Config to methods on the Subscriptions types func (b *Base) SetEnabledSubscriptions() { b.settingsMutex.Lock() defer b.settingsMutex.Unlock() - subConfig := b.Config.Features.Enabled.Subscriptions - if len(subConfig) == 0 { - for _, s := range b.Features.Enabled.Subscriptions { - // DO NOT COMMIT - //b.Config.Features.Enabled.Subscriptions = append(b.Config.Features.Enabled.Subscriptions, config.EnabledSubscriptionConfig(s)) - _ = s - } + if len(b.Config.Features.Enabled.Subscriptions) == 0 { + b.Config.Features.Enabled.Subscriptions = b.Config.Features.Enabled.Subscriptions return } - subs := make([]subscription.Subscription, 0, len(subConfig)) - for _, s := range subConfig { - //subs = append(subs, subscription.Subscription(s)) - // DO NOT COMMIT - _ = s - } - b.Features.Enabled.Subscriptions = subs + b.Features.Enabled.Subscriptions = b.Config.Features.Enabled.Subscriptions if b.Verbose { - names := make([]string, 0, len(subs)) - for _, s := range subs { + names := make([]string, 0, len(b.Features.Enabled.Subscriptions)) + for _, s := range b.Features.Enabled.Subscriptions { names = append(names, s.Channel) } log.Debugf(log.ExchangeSys, "Set %v 'Subscriptions' to %v", b.Name, strings.Join(names, ", "))