mirror of
https://github.com/c9s/bbgo.git
synced 2024-09-20 08:11:08 +00:00
okex: fix order book subscription channels
This commit is contained in:
parent
7bde48adce
commit
de7bf31b24
|
@ -81,9 +81,6 @@ func convertIntervalToCandle(interval types.Interval) string {
|
|||
}
|
||||
|
||||
func convertSubscription(s types.Subscription) (WebsocketSubscription, error) {
|
||||
// binance uses lower case symbol name,
|
||||
// for kline, it's "<symbol>@kline_<interval>"
|
||||
// for depth, it's "<symbol>@depth OR <symbol>@depth@100ms"
|
||||
switch s.Channel {
|
||||
case types.KLineChannel:
|
||||
// Channel names are:
|
||||
|
@ -93,17 +90,32 @@ func convertSubscription(s types.Subscription) (WebsocketSubscription, error) {
|
|||
}, nil
|
||||
|
||||
case types.BookChannel:
|
||||
if s.Options.Depth != types.DepthLevel400 {
|
||||
return WebsocketSubscription{}, fmt.Errorf("%s depth not supported", s.Options.Depth)
|
||||
ch := ChannelBooks
|
||||
|
||||
switch s.Options.Depth {
|
||||
case types.DepthLevelFull:
|
||||
ch = ChannelBooks
|
||||
|
||||
case types.DepthLevelMedium:
|
||||
ch = ChannelBooks50
|
||||
|
||||
case types.DepthLevel50:
|
||||
ch = ChannelBooks50
|
||||
|
||||
case types.DepthLevel5:
|
||||
ch = ChannelBooks5
|
||||
|
||||
case types.DepthLevel1:
|
||||
ch = ChannelBooks1
|
||||
}
|
||||
|
||||
return WebsocketSubscription{
|
||||
Channel: ChannelBooks,
|
||||
Channel: ch,
|
||||
InstrumentID: toLocalSymbol(s.Symbol),
|
||||
}, nil
|
||||
case types.BookTickerChannel:
|
||||
return WebsocketSubscription{
|
||||
Channel: ChannelBook5,
|
||||
Channel: ChannelBooks5,
|
||||
InstrumentID: toLocalSymbol(s.Symbol),
|
||||
}, nil
|
||||
case types.MarketTradeChannel:
|
||||
|
|
|
@ -15,8 +15,25 @@ import (
|
|||
type Channel string
|
||||
|
||||
const (
|
||||
ChannelBooks Channel = "books"
|
||||
ChannelBook5 Channel = "book5"
|
||||
// books: 400 depth levels will be pushed in the initial full snapshot.
|
||||
// Incremental data will be pushed every 100 ms for the changes in the order book during that period of time.
|
||||
ChannelBooks Channel = "books"
|
||||
|
||||
// ChannelBooks5 is books5
|
||||
// 5 depth levels snapshot will be pushed every time.
|
||||
// Snapshot data will be pushed every 100 ms when there are changes in the 5 depth levels snapshot.
|
||||
ChannelBooks5 Channel = "books5"
|
||||
|
||||
// ChannelBooks50 is books50-l2-tbt:
|
||||
// 50 depth levels will be pushed in the initial full snapshot.
|
||||
// Incremental data will be pushed every 10 ms for the changes in the order book during that period of time.
|
||||
ChannelBooks50 Channel = "books50-l2-tbt"
|
||||
|
||||
// ChannelBooks1 is bbo-tbt
|
||||
// 1 depth level snapshot will be pushed every time.
|
||||
// Snapshot data will be pushed every 10 ms when there are changes in the 1 depth level snapshot.
|
||||
ChannelBooks1 Channel = "bbo-tbt"
|
||||
|
||||
ChannelCandlePrefix Channel = "candle"
|
||||
ChannelAccount Channel = "account"
|
||||
ChannelMarketTrades Channel = "trades"
|
||||
|
@ -44,7 +61,7 @@ func parseWebSocketEvent(in []byte) (interface{}, error) {
|
|||
case ChannelAccount:
|
||||
return parseAccount(event.Data)
|
||||
|
||||
case ChannelBooks, ChannelBook5:
|
||||
case ChannelBooks, ChannelBooks5:
|
||||
var bookEvent BookEvent
|
||||
err = json.Unmarshal(event.Data, &bookEvent.Data)
|
||||
if err != nil {
|
||||
|
|
|
@ -303,7 +303,7 @@ func (s *Stream) dispatchEvent(e interface{}) {
|
|||
|
||||
case *BookEvent:
|
||||
// there's "books" for 400 depth and books5 for 5 depth
|
||||
if et.channel != ChannelBook5 {
|
||||
if et.channel != ChannelBooks5 {
|
||||
s.EmitBookEvent(*et)
|
||||
}
|
||||
s.EmitBookTickerUpdate(et.BookTicker())
|
||||
|
|
Loading…
Reference in New Issue
Block a user