Maintaining Order Book via WebSocket
To maintain a local copy of the order book with minimal latency, use the WebSocket 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
emitPublicOrderBookrequest to obtain a full snapshot. - Apply each subsequent
publicOrderBookDeltaupdate in the order received to keep your local copy synchronized.
Note: ForpublicOrderBookDeltamessages, thequantityfield represents the absolute value at the specified price level. A value of0indicates that the price level should be removed from your local order book.