FEATURE: [binance] add update when first receive the orderbook event

This commit is contained in:
kbearXD 2024-11-13 15:33:03 +08:00
parent ce6667268c
commit f8bd8e4164

View File

@ -86,17 +86,7 @@ func NewStream(ex *Exchange, client *binance.Client, futuresClient *futures.Clie
stream.OnDepthEvent(func(e *DepthEvent) {
f, ok := stream.depthBuffers[e.Symbol]
if ok {
err := f.AddUpdate(types.SliceOrderBook{
Symbol: e.Symbol,
Time: e.EventBase.Time.Time(),
Bids: e.Bids,
Asks: e.Asks,
}, e.FirstUpdateID, e.FinalUpdateID)
if err != nil {
log.WithError(err).Errorf("found missing %s update event", e.Symbol)
}
} else {
if !ok {
f = depth.NewBuffer(func() (types.SliceOrderBook, int64, error) {
log.Infof("fetching %s depth...", e.Symbol)
return ex.QueryDepth(context.Background(), e.Symbol)
@ -113,6 +103,15 @@ func NewStream(ex *Exchange, client *binance.Client, futuresClient *futures.Clie
})
stream.depthBuffers[e.Symbol] = f
}
if err := f.AddUpdate(types.SliceOrderBook{
Symbol: e.Symbol,
Time: e.EventBase.Time.Time(),
Bids: e.Bids,
Asks: e.Asks,
}, e.FirstUpdateID, e.FinalUpdateID); err != nil {
log.WithError(err).Errorf("found missing %s update event", e.Symbol)
}
})
stream.OnOutboundAccountPositionEvent(stream.handleOutboundAccountPositionEvent)