Skip to content

Add optional orderbook feature for snapshot-plus-diff depth sync - #292

Open
Mattbusel wants to merge 1 commit into
ccxt:masterfrom
tensorust-ai:deps/crypto-orderbook-depth-sync
Open

Mattbusel wants to merge 1 commit into
ccxt:masterfrom
tensorust-ai:deps/crypto-orderbook-depth-sync

Conversation

@Mattbusel

Copy link
Copy Markdown

The depth stream gives DepthOrderBookEvent diffs with f64 prices, and the crate has no snapshot-plus-diff sync, so everyone who keeps a local book writes the U/u/pu handshake by hand. Get it wrong once and the book keeps a cancelled bid without any error.

This adds an opt-in orderbook feature with From conversions from DepthOrderBookEvent and the spot and futures OrderBook snapshots into crypto_orderbook::BookSync. BookSync buffers events, applies the snapshot and checks each event's sequence: U on spot, pu on USD-M. On a gap it clears the book and asks for a new snapshot. Prices become exact Decimals. Tests cover a dropped spot diff and a futures pu break.

New optional dependency: crypto-orderbook = { version = "0.5.2", default-features = false } (serde, serde_json, rust_decimal, thiserror; no async runtime). Default builds are unchanged.

crypto-orderbook is maintained by Matthew Busel.

Disclosure: I maintain crypto-orderbook.

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.

1 participant