Skip to content

Commit

Permalink
Kucoin: Fix checkSubscriptions and coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Jul 16, 2024
1 parent b45bf06 commit a4b8c9a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
34 changes: 34 additions & 0 deletions exchanges/kucoin/kucoin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{ //nolint:govet // Intentional shadow to avoid future copy/paste mistakes
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)
Expand Down
5 changes: 4 additions & 1 deletion exchanges/kucoin/kucoin_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down

0 comments on commit a4b8c9a

Please sign in to comment.