Skip to main contentMaintaining Order Book via WebSocket
To maintain a local copy of the order book with minimal latency, use the WebSocket v2 API to receive both snapshots and delta updates. This enables your trading logic to react to real-time market changes efficiently.
Steps to Maintain a Local Order Book:
- Connect to the WebSocket and subscribe to the Order Book Stream to receive real-time updates.
- Initialize your local order book by sending an
emitOrderBook request to obtain a full snapshot.
- Apply each subsequent
orderBookDelta update in the order received to keep your local copy synchronized.
Note: For orderBookDelta messages, the quantity field represents the absolute value at the specified price level. A value of 0 indicates that the price level should be removed from your local order book.
REST and WebSocket Hybrid Approach
For users utilizing the legacy Order Book WebSocket, the order book can be maintained by combining REST and WebSocket APIs:
- Connect to the Order Book WebSocket to receive an initial full snapshot, followed by real-time delta updates.
- To refresh your local order book snapshot without disconnecting, use the Get Order Book REST endpoint as needed.