Skip to main content
Use the REST snapshot when you need the current book once. Combine it with the depth:SYMBOL WebSocket stream when your application must maintain a live local copy.

Read a snapshot

Bids are sorted from highest to lowest price. Asks are sorted from lowest to highest. Each level contains the total remaining quantity at that price; individual orders are not exposed.

Combine the snapshot and stream

The depth stream contains only levels that changed, so it cannot initialize a complete book by itself.
1

Subscribe and buffer

Connect to WebSocket streams, subscribe to depth:SYMBOL, and buffer every message without applying it yet.
2

Fetch a snapshot

Request GET /markets/:symbol/orderbook while buffering continues.
3

Discard covered updates

Discard buffered messages whose lastUpdateId is less than or equal to the snapshot’s lastUpdateId.
4

Apply the remainder

Apply the remaining buffered messages in arrival order, then apply new messages as they arrive.
A depth update replaces the quantity at a price level; it is not a delta to add. Remove the level when the received quantity represents zero.
Store prices as strings or scaled integers rather than JavaScript numbers. A simple implementation can use one map for bids and another for asks, keyed by the exact price string.

Recover after a disconnect

Do not continue from the old local book after reconnecting. Resubscribe, start buffering again, fetch a fresh snapshot, and repeat the synchronization procedure.