binance: buffer depth events

This commit is contained in:
c9s 2021-05-26 01:05:12 +08:00
parent edeaa597f1
commit 44ff833c91

View File

@ -3,6 +3,7 @@ package binance
import ( import (
"context" "context"
"sync" "sync"
"time"
"github.com/adshao/go-binance/v2" "github.com/adshao/go-binance/v2"
) )
@ -52,6 +53,12 @@ func (f *DepthFrame) bufferEvent(e DepthEvent) {
} }
func (f *DepthFrame) loadDepthSnapshot() { func (f *DepthFrame) loadDepthSnapshot() {
if debugBinanceDepth {
log.Infof("buffering %s depth events...", f.Symbol)
}
time.Sleep(3 * time.Second)
if debugBinanceDepth { if debugBinanceDepth {
log.Infof("loading %s depth from the restful api", f.Symbol) log.Infof("loading %s depth from the restful api", f.Symbol)
} }
@ -115,7 +122,7 @@ func (f *DepthFrame) loadDepthSnapshot() {
// valid // valid
nextID := depth.FinalUpdateID + 1 nextID := depth.FinalUpdateID + 1
if firstEvent.FirstUpdateID > nextID || firstEvent.FinalUpdateID < nextID { if firstEvent.FirstUpdateID > nextID || firstEvent.FinalUpdateID < nextID {
log.Warn("miss matched final update id for order book, resetting depth...") log.Warn("MISMATCH final update id for order book, resetting depth...")
return return
} }