Skip to main content

WebSocket streams

Streams are selected in the URL path, not by a subscribe message. Connect to:

wss://api-mainnet.n1.xyz/ws/<stream>[&<stream>...]
wss://api-devnet.n1.xyz/ws/<stream>[&<stream>...]

Multiple streams are joined with & in the path segment, so one connection can carry everything a process needs.

Streams

StreamFormContents
Tradestrades@<symbol>Executed trades for a market
Orderbook deltasdeltas@<symbol>Incremental book updates for a market
Candlescandle@<symbol>:<resolution>OHLCV bars
Accountaccount@<accountId>Balance, position, and order updates
RFQ fillsrfq-fills@<market>RFQ fill requests and results
Vaultvault@<vaultId>Vault state updates
LiquidationsliquidationsLiquidation events, exchange-wide

Resolutions are 1, 5, 15, 30, 60, 4H, 1D, 1W, 1M.

Example — trades and deltas for BTCUSD plus one account, on one socket:

wss://api-mainnet.n1.xyz/ws/trades@BTCUSD&deltas@BTCUSD&account@42

Message envelope

Messages are JSON and identify their stream, so a multiplexed connection can be dispatched on the stream name. Values arrive as scaled integers: divide by the market's priceDecimals / sizeDecimals or the token's decimals from /info.

Keeping a book in sync

Deltas are incremental and carry an updateId. Buffer deltas, take a snapshot from GET /market/{market_id}/orderbook, drop buffered updates at or below the snapshot's updateId, then apply the rest in order. Re-snapshot if updateId continuity breaks.

Reconnecting

Assume disconnects. On reconnect, re-open the same stream URL and re-establish state from REST before trusting incremental updates: a snapshot for books, and account state for balances, positions, and orders. The TypeScript SDK handles reconnection and provides typed handlers if you would rather not build this yourself.

These materials are provided for informational purposes only and do not constitute financial, investment, legal, or tax advice, or an offer or solicitation to buy or sell any asset. Trading digital assets and derivatives involves substantial risk, including the possible loss of some or all capital. Products may not be available in all jurisdictions. Users are responsible for evaluating suitability and complying with applicable laws.