Subscribe
Subscribe to real-time streaming updates for market data and account activity. Uses server-side streaming for efficient one-way data push.
STREAM
Subscribe🔐 Auth RequiredOpens a server-side streaming connection for real-time updates. The server pushes updates as they occur. For bidirectional streaming (order submission), use TradingStream instead.
Request
| Parameter | Type |
|---|---|
marketsrequired | string[] |
orderbookoptional | bool |
tradesoptional | bool |
positionsoptional | bool |
ordersoptional | bool |
fillsoptional | bool |
fundingoptional | bool |
Response
Returns a stream of updates. Each message has a type field indicating the update type.
| Field | Type |
|---|---|
type | UpdateType |
market | string |
data | object |
timestamp | uint64 |
sequence | uint64 |
Example
Requesttypescript
// Subscribe to all updates for RLM-PERPconst stream = await client.subscribe({markets: ['RLM-PERP'],orderbook: true,trades: true,positions: true,orders: true,fills: true,});// Handle updatesstream.on('orderbook', (update) => {console.log('Orderbook update:', update.market);console.log(' Bids:', update.bids.length);console.log(' Asks:', update.asks.length);});stream.on('trade', (trade) => {console.log('Trade:', trade.price, 'x', trade.size);});stream.on('position', (position) => {console.log('Position update:', position.market, position.unrealizedPnl);});stream.on('order', (order) => {console.log('Order update:', order.orderId, order.status);});stream.on('fill', (fill) => {console.log('Fill:', fill.price, 'x', fill.size);});// Cleanupstream.close();
Update Types
Orderbook Update
Incremental orderbook changes (not full snapshots):
json
{"type": "ORDERBOOK","market": "RLM-PERP","data": {"bids": [{ "price": 99.50, "size": 15.0 }, // Updated level{ "price": 99.25, "size": 0.0 } // Removed level (size=0)],"asks": [{ "price": 100.00, "size": 12.0 }]},"sequence": 12345679,"timestamp": 1704067200000000000}
Trade Update
json
{"type": "TRADE","market": "RLM-PERP","data": {"price": 100.00,"size": 5.0,"side": "buy", // Taker side"tradeId": "123456"},"timestamp": 1704067200000000000}
Position Update
json
{"type": "POSITION","market": "RLM-PERP","data": {"side": "long","size": 10.0,"entryPrice": 95.50,"markPrice": 100.25,"unrealizedPnl": 47.50,"liquidationPrice": 76.40},"timestamp": 1704067200000000000}
Order Update
json
{"type": "ORDER","market": "RLM-PERP","data": {"orderId": "12345678","status": "PARTIALLY_FILLED","filledSize": 5.0,"remainingSize": 5.0},"timestamp": 1704067200000000000}
Fill Update
json
{"type": "FILL","market": "RLM-PERP","data": {"orderId": "12345678","fillId": "987654","price": 100.00,"size": 5.0,"side": "buy","fee": 0.05,"role": "maker"},"timestamp": 1704067200000000000}
Sequence Numbers
Use sequence numbers to detect missed updates. If you see a gap, re-fetch the full snapshot (e.g., GetOrderbook) and continue from there.
Connection Management
- Heartbeats — The server sends periodic heartbeat messages. If no message is received for 30 seconds, reconnect.
- Reconnection — On disconnect, reconnect with exponential backoff. Re-fetch full state before resuming.
- Multiple subscriptions — You can subscribe to multiple markets in a single connection.
HFT Streaming
For high-frequency trading with bidirectional streaming (order submission without separate API calls), use TradingStream instead.