From e95429bbc3600609c53a5ea349b4b392773cfeb9 Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 19 May 2021 01:02:41 +0800 Subject: [PATCH] binance: save newer events for later usage --- pkg/exchange/binance/depthframe.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/exchange/binance/depthframe.go b/pkg/exchange/binance/depthframe.go index 744cb3ba3..4ddb9d2bd 100644 --- a/pkg/exchange/binance/depthframe.go +++ b/pkg/exchange/binance/depthframe.go @@ -72,9 +72,9 @@ func (f *DepthFrame) loadDepthSnapshot() { // if the head event is newer than the depth we got, // then there are something missed, we need to restart the process. if len(events) > 0 { - e := events[0] - if e.FirstUpdateID > depth.FinalUpdateID+1 { - log.Warn("miss matched final update id for order book") + firstEvent := events[0] + if firstEvent.FirstUpdateID > depth.FinalUpdateID+1 { + log.Warn("miss matched final update id for order book, resetting depth...") f.SnapshotDepth = nil f.BufEvents = nil f.mu.Unlock() @@ -138,6 +138,9 @@ func (f *DepthFrame) PushEvent(e DepthEvent) { } f.SnapshotDepth = nil + + // save the new event for later + f.BufEvents = append(f.BufEvents, e) f.mu.Unlock() return }