Skip to content

Commit

Permalink
fixup! Kucoin: Switch to sub templating
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Jul 12, 2024
1 parent 1b2c317 commit d0ff59a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
14 changes: 14 additions & 0 deletions exchanges/kucoin/kucoin_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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() {
Expand Down
25 changes: 11 additions & 14 deletions exchanges/kucoin/kucoin_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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:
Expand All @@ -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
})
Expand Down

0 comments on commit d0ff59a

Please sign in to comment.