GetOrderbook
Get a snapshot of the L2 orderbook for a specific market. Returns aggregated price levels with total size at each level.
GET
GetOrderbookPublicReturns the current orderbook state for a market. Bids are sorted descending by price, asks are sorted ascending.
Request
| Parameter | Type |
|---|---|
market_idrequired | uint32 |
depthoptional | uint32 |
Response
| Field | Type |
|---|---|
success | bool |
market_id | uint32 |
bids | PriceLevel[] |
asks | PriceLevel[] |
timestamp | uint64 |
sequence | uint64 |
Example
Requesttypescript
const orderbook = await client.getOrderbook('RLM-PERP', { depth: 10 });console.log('Best bid:', orderbook.bids[0]?.price);console.log('Best ask:', orderbook.asks[0]?.price);console.log('Spread:', orderbook.asks[0]?.price - orderbook.bids[0]?.price);// Process all levelsfor (const bid of orderbook.bids) {console.log(`Bid: ${bid.price} x ${bid.size}`);}
Responsejson
{"success": true,"marketId": 0,"bids": [{ "price": 99.50, "size": 10.5 },{ "price": 99.00, "size": 25.0 },{ "price": 98.50, "size": 50.0 }],"asks": [{ "price": 100.00, "size": 8.0 },{ "price": 100.50, "size": 15.0 },{ "price": 101.00, "size": 30.0 }],"timestamp": 1704067200000000000,"sequence": 12345678}
PriceLevel Structure
| Field | Type | Description |
|---|---|---|
price | int64 | Price level (8 decimals) |
size | int64 | Total size at this level (8 decimals) |
Usage Notes
- L2 aggregation — Orders at the same price are combined into a single level. You see total size, not individual orders.
- Sequence numbers — Use the sequence field to detect gaps when processing streaming updates.
- Depth limits — Maximum depth is 100 levels per side. Default is 20.
Real-time Updates
For real-time orderbook updates, use the Subscribe endpoint with orderbook: true. This provides incremental updates rather than full snapshots.