Skip to content

Commit 452e761

Browse files
authored
Merge pull request #1821 from c9s/kbearXD/max/depth-buffer
FEAUTRE: [max] update buffer second
2 parents 8e326d9 + bbfd89b commit 452e761

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

pkg/depth/buffer.go

+6
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ func (b *Buffer) AddUpdate(o types.SliceOrderBook, firstUpdateID int64, finalArg
112112
return nil
113113
}
114114

115+
if u.FinalUpdateID <= b.finalUpdateID {
116+
log.Infof("the final update id %d of event is less than equal to the final update id %d of the snapshot, skip", u.FinalUpdateID, b.finalUpdateID)
117+
b.mu.Unlock()
118+
return nil
119+
}
120+
115121
// if there is a missing update, we should reset the snapshot and re-fetch the snapshot
116122
if u.FirstUpdateID > b.finalUpdateID+1 {
117123
// emitReset will reset the once outside the mutex lock section

pkg/exchange/max/stream.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func (s *Stream) handleBookEvent(ex *Exchange) func(e max.BookEvent) {
236236
// the depth of websocket orderbook event is 50 by default, so we use 50 as limit here
237237
return ex.QueryDepth(context.Background(), e.Market, bookDepth)
238238
})
239-
f.SetBufferingPeriod(time.Second)
239+
f.SetBufferingPeriod(3 * time.Second)
240240
f.OnReady(func(snapshot types.SliceOrderBook, updates []depth.Update) {
241241
s.EmitBookSnapshot(snapshot)
242242
for _, u := range updates {

0 commit comments

Comments
 (0)