Subscribe

Subscribe to real-time streaming updates for market data and account activity. Uses server-side streaming for efficient one-way data push.

STREAMSubscribe🔐 Auth

Opens 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

ParameterTypeDescription
marketsrequiredstring[]Array of market symbols to subscribe to
orderbookoptionalboolSubscribe to orderbook updatesDefault: false
tradesoptionalboolSubscribe to trade updatesDefault: false
positionsoptionalboolSubscribe to position updatesDefault: false
ordersoptionalboolSubscribe to order status updatesDefault: false
fillsoptionalboolSubscribe to fill notificationsDefault: false
fundingoptionalboolSubscribe to funding rate updatesDefault: false

Response

Returns a stream of updates. Each message has a type field indicating the update type.

FieldTypeDescription
typeUpdateTypeORDERBOOK, TRADE, POSITION, ORDER, FILL, FUNDING
marketstringMarket symbol this update relates to
dataobjectUpdate payload (structure depends on type)
timestampuint64Server timestamp (nanoseconds)
sequenceuint64Sequence number for ordering

Example

Request

// Subscribe to all updates for RLM-PERP
const stream = await client.subscribe({
markets: ['RLM-PERP'],
orderbook: true,
trades: true,
positions: true,
orders: true,
fills: true,
});
// Handle updates
stream.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);
});
// Cleanup
stream.close();

Update Types

Orderbook Update

Incremental orderbook changes (not full snapshots):

{
"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

{
"type": "TRADE",
"market": "RLM-PERP",
"data": {
"price": 100.00,
"size": 5.0,
"side": "buy", // Taker side
"tradeId": "123456"
},
"timestamp": 1704067200000000000
}

Position Update

{
"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

{
"type": "ORDER",
"market": "RLM-PERP",
"data": {
"orderId": "12345678",
"status": "PARTIALLY_FILLED",
"filledSize": 5.0,
"remainingSize": 5.0
},
"timestamp": 1704067200000000000
}

Fill Update

{
"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.