pkg/exchange: support order book depth 200 on bybit

This commit is contained in:
Edwin 2023-10-12 11:11:26 +08:00
parent d617bf8ae5
commit ef582f6e52
3 changed files with 29 additions and 2 deletions

View File

@ -318,8 +318,12 @@ func (s *Stream) convertSubscription(sub types.Subscription) (string, error) {
case types.BookChannel:
depth := types.DepthLevel1
if len(sub.Options.Depth) > 0 && sub.Options.Depth == types.DepthLevel50 {
depth = types.DepthLevel50
switch sub.Options.Depth {
case types.DepthLevel50:
depth = sub.Options.Depth
case types.DepthLevel200:
depth = sub.Options.Depth
}
return genTopic(TopicTypeOrderBook, depth, sub.Symbol), nil

View File

@ -395,6 +395,28 @@ func Test_convertSubscription(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, genTopic(TopicTypeOrderBook, types.DepthLevel1, "BTCUSDT"), res)
})
t.Run("BookChannel.DepthLevel50", func(t *testing.T) {
res, err := s.convertSubscription(types.Subscription{
Symbol: "BTCUSDT",
Channel: types.BookChannel,
Options: types.SubscribeOptions{
Depth: types.DepthLevel50,
},
})
assert.NoError(t, err)
assert.Equal(t, genTopic(TopicTypeOrderBook, types.DepthLevel50, "BTCUSDT"), res)
})
t.Run("BookChannel.DepthLevel200", func(t *testing.T) {
res, err := s.convertSubscription(types.Subscription{
Symbol: "BTCUSDT",
Channel: types.BookChannel,
Options: types.SubscribeOptions{
Depth: types.DepthLevel200,
},
})
assert.NoError(t, err)
assert.Equal(t, genTopic(TopicTypeOrderBook, types.DepthLevel200, "BTCUSDT"), res)
})
t.Run("BookChannel. with default depth", func(t *testing.T) {
res, err := s.convertSubscription(types.Subscription{
Symbol: "BTCUSDT",

View File

@ -521,6 +521,7 @@ const (
DepthLevel5 Depth = "5"
DepthLevel20 Depth = "20"
DepthLevel50 Depth = "50"
DepthLevel200 Depth = "200"
)
type Speed string