mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
Merge pull request #1812 from c9s/kbearXD/max/orderbook
FEAUTRE: [max] reset book if receive both empty asks and bids
This commit is contained in:
commit
ce6667268c
|
@ -217,17 +217,7 @@ func (s *Stream) handleBookEvent(ex *Exchange) func(e max.BookEvent) {
|
|||
return func(e max.BookEvent) {
|
||||
symbol := toGlobalSymbol(e.Market)
|
||||
f, ok := s.depthBuffers[symbol]
|
||||
if ok {
|
||||
err := f.AddUpdate(types.SliceOrderBook{
|
||||
Symbol: toGlobalSymbol(e.Market),
|
||||
Time: e.Time(),
|
||||
Bids: e.Bids,
|
||||
Asks: e.Asks,
|
||||
}, e.FirstUpdateID, e.LastUpdateID)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("found missing %s update event", e.Market)
|
||||
}
|
||||
} else {
|
||||
if !ok {
|
||||
f = depth.NewBuffer(func() (types.SliceOrderBook, int64, error) {
|
||||
log.Infof("fetching %s depth...", e.Market)
|
||||
// the depth of websocket orderbook event is 50 by default, so we use 50 as limit here
|
||||
|
@ -245,6 +235,22 @@ func (s *Stream) handleBookEvent(ex *Exchange) func(e max.BookEvent) {
|
|||
})
|
||||
s.depthBuffers[symbol] = f
|
||||
}
|
||||
|
||||
// if we receive orderbook event with both asks and bids are empty, it means we need to rebuild this orderbook
|
||||
shouldReset := len(e.Asks) == 0 && len(e.Bids) == 0
|
||||
if shouldReset {
|
||||
f.Reset()
|
||||
return
|
||||
}
|
||||
|
||||
if err := f.AddUpdate(types.SliceOrderBook{
|
||||
Symbol: symbol,
|
||||
Time: e.Time(),
|
||||
Bids: e.Bids,
|
||||
Asks: e.Asks,
|
||||
}, e.FirstUpdateID, e.LastUpdateID); err != nil {
|
||||
log.WithError(err).Errorf("found missing %s update event", e.Market)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user