Skip to content

Binance Spot order book support - #188

Draft
hacheigriega wants to merge 2 commits into
mainfrom
feat/binance-spot-book
Draft

hacheigriega wants to merge 2 commits into
mainfrom
feat/binance-spot-book

Conversation

@hacheigriega

Copy link
Copy Markdown
Contributor

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's subscribe invokes snapshotLoop, which fetches a snapshot every DEPTH_SNAPSHOT_RETRY seconds until a snapshot is "promoted" to a live book.

This is how a snapshot is promoted:

A snapshot contains a lastUpdateId field, which we compare against the incoming diff’s U (first update ID) and u (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

@hacheigriega
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants