From f8bd8e41644ab54f140bd2c9494465ae9678b593 Mon Sep 17 00:00:00 2001 From: kbearXD Date: Wed, 13 Nov 2024 15:33:03 +0800 Subject: [PATCH] FEATURE: [binance] add update when first receive the orderbook event --- pkg/exchange/binance/stream.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/pkg/exchange/binance/stream.go b/pkg/exchange/binance/stream.go index 61bfc8a7b..91e40cc48 100644 --- a/pkg/exchange/binance/stream.go +++ b/pkg/exchange/binance/stream.go @@ -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)