diff --git a/exchanges/kucoin/kucoin_test.go b/exchanges/kucoin/kucoin_test.go index fd38824a1e6..55978d25b98 100644 --- a/exchanges/kucoin/kucoin_test.go +++ b/exchanges/kucoin/kucoin_test.go @@ -15,6 +15,7 @@ import ( "github.com/stretchr/testify/require" "github.com/thrasher-corp/gocryptotrader/common" "github.com/thrasher-corp/gocryptotrader/common/key" + "github.com/thrasher-corp/gocryptotrader/config" "github.com/thrasher-corp/gocryptotrader/core" "github.com/thrasher-corp/gocryptotrader/currency" exchange "github.com/thrasher-corp/gocryptotrader/exchanges" @@ -2087,6 +2088,39 @@ func TestGenerateOtherSubscriptions(t *testing.T) { } } +// TestCheckSubscriptions ensures checkSubscriptions upgrades user config correctly +func TestCheckSubscriptions(t *testing.T) { + t.Parallel() + + ku := &Kucoin{ + Base: exchange.Base{ + Config: &config.Exchange{ + Features: &config.FeaturesConfig{}, + }, + Features: exchange.Features{ + Subscriptions: subscription.List{ + {Channel: "ticker"}, + {Channel: "allTrades"}, + {Channel: "orderbook", Interval: kline.HundredMilliseconds}, + {Channel: "/contractMarket/tickerV2:%s"}, + {Channel: "/contractMarket/level2Depth50:%s"}, + {Channel: "/margin/fundingBook:%s", Authenticated: true}, + {Channel: "/account/balance", Authenticated: true}, + {Channel: "/margin/position", Authenticated: true}, + {Channel: "/margin/loan:%s", Authenticated: true}, + {Channel: "/contractMarket/tradeOrders", Authenticated: true}, + {Channel: "/contractMarket/advancedOrders", Authenticated: true}, + {Channel: "/contractAccount/wallet", Authenticated: true}, + }, + }, + }, + } + + ku.checkSubscriptions() + testsubs.EqualLists(t, defaultSubscriptions, ku.Features.Subscriptions) + testsubs.EqualLists(t, defaultSubscriptions, ku.Config.Features.Subscriptions) +} + func TestGetAvailableTransferChains(t *testing.T) { t.Parallel() sharedtestvalues.SkipTestIfCredentialsUnset(t, ku) diff --git a/exchanges/kucoin/kucoin_websocket.go b/exchanges/kucoin/kucoin_websocket.go index 491e12fed3a..dfed09c118c 100644 --- a/exchanges/kucoin/kucoin_websocket.go +++ b/exchanges/kucoin/kucoin_websocket.go @@ -1588,6 +1588,7 @@ func (ku *Kucoin) CalculateAssets(topic string, cp currency.Pair) ([]asset.Item, // checkSubscriptions looks for any backwards incompatibilities with missing assets func (ku *Kucoin) checkSubscriptions() { for _, s := range ku.Features.Subscriptions { + s.Channel = strings.TrimSuffix(s.Channel, ":%s") if s.Asset != asset.Empty { continue } @@ -1608,7 +1609,9 @@ func (ku *Kucoin) checkSubscriptions() { } ku.Features.Subscriptions = slices.DeleteFunc(ku.Features.Subscriptions, func(s *subscription.Subscription) bool { switch s.Channel { - case "/contractMarket/level2Depth50:%s", "/contractMarket/tickerV2:%s": + case "/contractMarket/level2Depth50", // Replaced by subsctiption.Orderbook for asset.All + "/contractMarket/tickerV2", // Replaced by subscription.Ticker for asset.All + "/margin/fundingBook": // Deprecated and removed return true case subscription.AllTradesChannel: return s.Asset == asset.Empty