Kucoin: Abstract a subscriptionNames for assets solution (#1669)

This commit is contained in:
Gareth Kirwan
2024-10-23 03:05:47 +02:00
committed by GitHub
parent 2232340d49
commit 4fc1bf0ad1
2 changed files with 40 additions and 13 deletions

View File

@@ -4335,3 +4335,23 @@ func TestCancelBatchOrders(t *testing.T) {
_, err := ku.CancelBatchOrders(context.Background(), nil)
assert.ErrorIs(t, common.ErrFunctionNotSupported, err)
}
func TestChannelName(t *testing.T) {
t.Parallel()
for _, tt := range []struct {
a asset.Item
ch string
exp string
}{
{asset.Futures, futuresOrderbookDepth50Channel, futuresOrderbookDepth50Channel},
{asset.Futures, subscription.OrderbookChannel, futuresOrderbookDepth5Channel},
{asset.Futures, subscription.CandlesChannel, marketCandlesChannel},
{asset.Futures, subscription.TickerChannel, futuresTickerChannel},
{asset.Spot, subscription.OrderbookChannel, marketOrderbookDepth5Channel},
{asset.Spot, subscription.AllTradesChannel, marketMatchChannel},
{asset.Spot, subscription.CandlesChannel, marketCandlesChannel},
{asset.Spot, subscription.TickerChannel, marketTickerChannel},
} {
assert.Equal(t, tt.exp, channelName(&subscription.Subscription{Channel: tt.ch}, tt.a))
}
}

View File

@@ -88,6 +88,19 @@ var (
maxWSOrderbookWorkers = 10
)
var subscriptionNames = map[asset.Item]map[string]string{
asset.Futures: {
subscription.TickerChannel: futuresTickerChannel,
subscription.OrderbookChannel: futuresOrderbookDepth5Channel, // This does not require a REST request to get the orderbook.
},
asset.All: {
subscription.TickerChannel: marketTickerChannel,
subscription.OrderbookChannel: marketOrderbookDepth5Channel, // This does not require a REST request to get the orderbook.
subscription.CandlesChannel: marketCandlesChannel,
subscription.AllTradesChannel: marketMatchChannel,
},
}
var defaultSubscriptions = subscription.List{
{Enabled: true, Asset: asset.All, Channel: subscription.TickerChannel},
{Enabled: true, Asset: asset.All, Channel: subscription.OrderbookChannel, Interval: kline.HundredMilliseconds},
@@ -1664,21 +1677,15 @@ func (ku *Kucoin) checkSubscriptions() {
// channelName returns the correct channel name for the asset
func channelName(s *subscription.Subscription, a asset.Item) string {
switch s.Channel {
case subscription.TickerChannel:
if a == asset.Futures {
return futuresTickerChannel
if byAsset, hasAsset := subscriptionNames[a]; hasAsset {
if name, ok := byAsset[s.Channel]; ok {
return name
}
return marketTickerChannel
case subscription.OrderbookChannel:
if a == asset.Futures {
return futuresOrderbookDepth5Channel
}
if allAssets, hasAll := subscriptionNames[asset.All]; hasAll {
if name, ok := allAssets[s.Channel]; ok {
return name
}
return marketOrderbookDepth5Channel // This does not require a REST request to get the orderbook.
case subscription.CandlesChannel:
return marketCandlesChannel // No support in GCT yet for Futures candles
case subscription.AllTradesChannel:
return marketMatchChannel // No support in GCT yet for Futures all trades
}
return s.Channel
}