Skip to main content

Custom Order Book

Goal: Use the raw order book data from xRocket's API to build a custom, real-time visualization outside the default UI.

Key xRocket API Features Used:

  • Public Market Data Endpoint: GET /api/v1/orderbook (for initial load).
  • WebSocket API: For real-time updates.
warning

Order book delta updates are incremental. If your WebSocket connection drops and reconnects, you must re-fetch the full order book snapshot via the REST endpoint before applying new deltas, otherwise your local state will be out of sync.

Workflow:

  1. Initial Load: The client application makes an initial GET request to the order book endpoint for the desired symbol (TON-USDT) to populate the initial data display.
  2. WebSocket Connection: The application opens a WebSocket connection to the xRocket stream endpoint.
  3. Real-Time Updates: The app subscribes to the order book channel for TON-USDT. It constantly receives delta updates (changes to individual bids/asks).
  4. Visualization Update: The application processes the deltas in real-time, updating the visualization (e.g., a chart or table) without needing to reload the entire dataset, creating a smooth user experience.
tip

When a delta update contains a quantity of 0 for a price level, that level has been fully consumed and should be removed from your local order book.