Repository navigation
Binance Spot order book support - #188
Draft
hacheigriega wants to merge 2 commits into
Draft
hacheigriega wants to merge 2 commits into
hacheigriega wants to merge 2 commits into
Conversation
hacheigriega
marked this pull request as draft
October 14, 2026 02:21
The trailing space in the reseed comment failed biome, and the venue table had dropped notes that still apply. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Binance Spot order book support so that information about book depth can be provided. Binance Futures will be addressed in a separate PR since Binance links update events differently for Futures.
Explanation of Changes
Binance requires that a seed snapshot is retrieved separately from a REST endpoint. Diffs (= updates) are then subscribed through a WebSocket stream.
VenueWS'ssubscribeinvokessnapshotLoop, which fetches a snapshot everyDEPTH_SNAPSHOT_RETRYseconds until a snapshot is "promoted" to a live book.This is how a snapshot is promoted:
A snapshot contains a
lastUpdateIdfield, which we compare against the incoming diff’sU(first update ID) andu(final update ID) to determine if the diff “continues” the snapshot. If the diff does not continue the snapshot, the diff may be behind the snapshot, in which case we ignore it, or the diff may be too far ahead of the snapshot (a “gap”), in which case we re-seed the snapshot.Diffs may also arrive before a snapshot, in which case we buffer them until a snapshot arrives.
A snapshot stays “pending” until we get a diff that continues it. Once we get such a diff, we promote the snapshot to a live order book by applying the buffered updates and begin serving the book by writing to the cache.
Reference
Related PRs and Issues
Related: #183