Market Data Flow
Discover a market, build an L2 order book, apply WebSocket updates, recover sequence gaps, and reconnect without losing state.
Use REST to discover markets or read a point-in-time book. Use WebSockets to keep a local order book current.
| Need | Interface |
|---|---|
| Find markets and tickers | GET /markets |
| Read one current L2 order book | GET /markets/{ticker}/orderbook |
| Maintain a live L2 order book | WebSocket API |
1. Choose a Market
Call REST GET /markets, then keep the ticker for each market you want to follow over WebSocket. Prices are YES-side dollar values. Quantities are contract quantities.
2. Connect
Open the WebSocket endpoint for your environment. Authenticate the HTTP upgrade with an API key signature and select the exact udx.json.<YYYY-MM-DD> subprotocol published in AsyncAPI. See Authentication and Versioning.
3. Subscribe
Send one subscribe command for the tickers you want:
{
"id": 1,
"cmd": "subscribe",
"params": {
"channels": ["orderbook"],
"tickers": ["UDX-EXAMPLE-MARKET"],
"level": "L2",
"depth": 25
}
}
UDX first returns a subscribed response with one subscription ID (sid) per ticker. It then sends an orderbook_snapshot for each subscription. Replace your local book with that snapshot.
Each sid has its own sequence beginning at 1. Track sequence numbers independently when one command subscribes to multiple markets.
4. Apply Updates
Each orderbook_update contains absolute replacements for one or more price levels:
- set the level to the supplied quantity; or
- remove the level when the quantity is
0.
Apply an update only when its seq is exactly one greater than the last message for that sid. Reapplying the same (sid, seq) has no effect.
5. Recover a Gap
If a sequence number skips ahead, stop applying updates for that sid and request a new snapshot:
{
"id": 2,
"cmd": "snapshot",
"params": {
"sids": [7]
}
}
The returned orderbook_snapshot uses the subscription’s next sequence number. Replace the complete local book, record that sequence, then resume applying later updates.
6. Reconnect
Subscriptions do not survive a disconnected session. Reconnect with a new signature, subscribe again, and replace local state with each new initial snapshot.