Skip to content

Commit

Permalink
Swich to external package for channel subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Nov 3, 2023
1 parent 662eda1 commit fdac336
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
3 changes: 2 additions & 1 deletion config/config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {

Check warning on line 318 in config/config_types.go

View workflow job for this annotation

GitHub Actions / lint

exported: exported type EnabledSubscriptionConfig should have comment or be unexported (revive)
Expand Down
22 changes: 5 additions & 17 deletions exchanges/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ", "))
Expand Down

0 comments on commit fdac336

Please sign in to comment.