From d0ff59a1490c6c03eda74222d3c368891dbb881d Mon Sep 17 00:00:00 2001 From: Gareth Kirwan Date: Fri, 12 Jul 2024 11:10:01 +0700 Subject: [PATCH] fixup! Kucoin: Switch to sub templating --- exchanges/kucoin/kucoin_websocket.go | 14 ++++++++++++++ exchanges/kucoin/kucoin_wrapper.go | 25 +++++++++++-------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/exchanges/kucoin/kucoin_websocket.go b/exchanges/kucoin/kucoin_websocket.go index 882c70f5c1f..120e5698d0c 100644 --- a/exchanges/kucoin/kucoin_websocket.go +++ b/exchanges/kucoin/kucoin_websocket.go @@ -19,6 +19,7 @@ import ( exchange "github.com/thrasher-corp/gocryptotrader/exchanges" "github.com/thrasher-corp/gocryptotrader/exchanges/account" "github.com/thrasher-corp/gocryptotrader/exchanges/asset" + "github.com/thrasher-corp/gocryptotrader/exchanges/kline" "github.com/thrasher-corp/gocryptotrader/exchanges/order" "github.com/thrasher-corp/gocryptotrader/exchanges/orderbook" "github.com/thrasher-corp/gocryptotrader/exchanges/request" @@ -83,6 +84,19 @@ var ( maxWSOrderbookWorkers = 10 ) +var defaultSubscriptions = subscription.List{ + {Enabled: true, Asset: asset.All, Channel: subscription.TickerChannel}, + {Enabled: true, Asset: asset.All, Channel: subscription.OrderbookChannel, Interval: kline.HundredMilliseconds}, + {Enabled: true, Asset: asset.Spot, Channel: subscription.AllTradesChannel}, + {Enabled: true, Asset: asset.Margin, Channel: subscription.AllTradesChannel}, + {Enabled: true, Asset: asset.Futures, Channel: futuresTradeOrderChannel, Authenticated: true}, + {Enabled: true, Asset: asset.Futures, Channel: futuresStopOrdersLifecycleEventChannel, Authenticated: true}, + {Enabled: true, Asset: asset.Futures, Channel: futuresAccountBalanceEventChannel, Authenticated: true}, + {Enabled: true, Asset: asset.Margin, Channel: marginPositionChannel, Authenticated: true}, + {Enabled: true, Asset: asset.Margin, Channel: marginLoanChannel, Authenticated: true}, + {Enabled: true, Channel: accountBalanceChannel, Authenticated: true}, +} + // WsConnect creates a new websocket connection. func (ku *Kucoin) WsConnect() error { if !ku.Websocket.IsEnabled() || !ku.IsEnabled() { diff --git a/exchanges/kucoin/kucoin_wrapper.go b/exchanges/kucoin/kucoin_wrapper.go index bc5bda76a37..8a5774b219c 100644 --- a/exchanges/kucoin/kucoin_wrapper.go +++ b/exchanges/kucoin/kucoin_wrapper.go @@ -145,18 +145,7 @@ func (ku *Kucoin) SetDefaults() { GlobalResultLimit: 1500, }, }, - Subscriptions: subscription.List{ - {Enabled: true, Asset: asset.All, Channel: subscription.TickerChannel}, - {Enabled: true, Asset: asset.All, Channel: subscription.OrderbookChannel, Interval: kline.HundredMilliseconds}, - {Enabled: true, Asset: asset.Spot, Channel: subscription.AllTradesChannel}, - {Enabled: true, Asset: asset.Margin, Channel: subscription.AllTradesChannel}, - {Enabled: true, Asset: asset.Futures, Channel: futuresTradeOrderChannel, Authenticated: true}, - {Enabled: true, Asset: asset.Futures, Channel: futuresStopOrdersLifecycleEventChannel, Authenticated: true}, - {Enabled: true, Asset: asset.Futures, Channel: futuresAccountBalanceEventChannel, Authenticated: true}, - {Enabled: true, Asset: asset.Margin, Channel: marginPositionChannel, Authenticated: true}, - {Enabled: true, Asset: asset.Margin, Channel: marginLoanChannel, Authenticated: true}, - {Enabled: true, Channel: accountBalanceChannel, Authenticated: true}, - }, + Subscriptions: defaultSubscriptions, } ku.Requester, err = request.New(ku.Name, common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout), @@ -2030,15 +2019,21 @@ func (ku *Kucoin) GetCurrencyTradeURL(_ context.Context, a asset.Item, cp curren } } -// checkSubscriptions looks for any backwards incompatibilities with subscriptions, notably missing assets +// checkSubscriptions looks for any backwards incompatibilities with missing assets func (ku *Kucoin) checkSubscriptions() { for _, s := range ku.Features.Subscriptions { if s.Asset != asset.Empty { continue } switch s.Channel { - case subscription.TickerChannel, subscription.AllTradesChannel, subscription.OrderbookChannel: + case subscription.TickerChannel, subscription.OrderbookChannel: s.Asset = asset.All + case subscription.AllTradesChannel: + for _, d := range defaultSubscriptions { + if d.Channel == s.Channel { + ku.Features.Subscriptions = append(ku.Features.Subscriptions, d) + } + } case futuresTradeOrderChannel, futuresStopOrdersLifecycleEventChannel, futuresAccountBalanceEventChannel: s.Asset = asset.Futures case marginPositionChannel, marginLoanChannel: @@ -2049,6 +2044,8 @@ func (ku *Kucoin) checkSubscriptions() { switch s.Channel { case "/contractMarket/level2Depth50:%s", "/contractMarket/tickerV2:%s": return true + case subscription.AllTradesChannel: + return s.Asset == asset.Empty } return false })