Streams
Subscribe to live trades, books, candles, tickers, marks and numbered account reports over WebSocket, merge order-book updates, resume account streams after a reconnect, and recover cleanly from gaps.
On this page
- Available streams
- Subscribing
- atlas.subscribe
- atlas.unsubscribe
- Account streams and sign-in
- Every event
- Sequence and snapshots
- Recovering from a gap
- Market streams
- stream.trades
- stream.order_book
- stream.candles
- stream.ticker
- stream.bbo
- stream.mark_price
- Account streams
- Report numbers
- Snapshots
- Resuming after a reconnect
- Filtering report types
- Heartbeats, gaps and rejects
- stream.orders
- stream.account
- When the server ends a stream
- stream.closed
- Slow consumers
- Heartbeats
A stream is a subscription on one WebSocket connection. You open it with atlas.subscribe, the server pushes stream.* notifications tagged with your subscriptionId, and it ends when you unsubscribe, the server sends stream.closed, or the connection drops. A market stream has no replay: if you miss something, you resubscribe and start from a fresh snapshot. The two account streams number their reports, so you can resume them where you left off.
- Market streams
/market/ws, no auth. Select a market bymarketId- Account streams
/account/ws. See sign-in- One subscribe
- Creates exactly one subscription
- Ordering
seqper subscription, starts at"1"- Order book
- One snapshot, then incremental updates to merge
- Recovery
- Market streams: resubscribe. Account streams: resume with
afterReportNo
Available streams
stream | Push method | Params | Endpoint | Payload | Snapshot first? |
|---|---|---|---|---|---|
trades | stream.trades | marketId | /market/ws | Trade[] | Yes |
order_book | stream.order_book | marketId, optional interval | /market/ws | OrderBookUpdate | Yes, then deltas |
candles | stream.candles | marketId, interval | /market/ws | Candle[] | Yes |
ticker | stream.ticker | marketId | /market/ws | Ticker | Yes |
mark_price | stream.mark_price | marketId (perps) | /market/ws | MarkPrice | Yes, if one exists |
bbo | stream.bbo | marketId | /market/ws | BBO | Yes |
orders | stream.orders | accountAddress, optional types and afterReportNo | /account/ws | Numbered order and fill reports | Yes, unless you resume |
account | stream.account | accountAddress, optional types and afterReportNo | /account/ws | Numbered balance, position, payment, wallet-state and account reports | Yes, unless you resume |
Funding payments arrive on stream.account as payment reports; there is no separate funding stream. Account health and advanced (TP/SL and TWAP) orders have no stream: read them with atlas.getAccountState and atlas.getAdvancedOrders.
If you need both market and account streams, open two connections: one to /market/ws, one to /account/ws.
Subscribing
atlas.subscribe
atlas.subscribeWebSocket/market/ws, /account/wsCreates one subscription on this connection. Takes a named params object.
streamenumrequiredtrades,order_book,candles,ticker,mark_price,bbo,ordersoraccount.marketIdinteger- Required for market streams: the market's id from
atlas.getSymbols. Ignored for account streams. intervalstring- For
candles, required:1m,5m,15m,1h,4hor1d. Fororder_book, optional: how often deltas arrive,0ms(every change) or50ms. Omit it for the default,50ms. An interval the service doesn't publish is-32602. Ignored otherwise. accountAddressAccountAddress- Required for
ordersandaccount. Ignored for market streams. typesstring[]ordersandaccountonly: the report types to receive. Omit for all.order,fillandrejectonorders;balance,position,payment,walletState,accountReportandrejectonaccount. See Filtering.afterReportNoUint64Stringordersandaccountonly: the last report number you hold on this stream for this account. The stream resumes after it instead of starting with a snapshot. See Resuming.
A market stream refuses a symbol param with -32602: select the market by marketId.
Result
subscribe result
subscriptionIdSubscriptionIdrequired- Opaque. Valid only on this connection.
snapshotSupportedbooleanrequiredtrueif asnapshot: trueevent follows straight away.
atlas.subscribeWebSocketconst ws = new WebSocket("wss://<ws-host>/market/ws");
ws.onopen = () => ws.send(JSON.stringify({
"jsonrpc": "2.0",
"id": 1,
"method": "atlas.subscribe",
"params": {
"stream": "order_book",
"marketId": 4294967297
}
}));
ws.onmessage = (ev) => {
const msg = JSON.parse(ev.data);
if (msg.id === 1) console.log(msg.result ?? msg.error);
};Press Send to see the response.| Error | When |
|---|---|
-32602 | Unknown stream, a stream not served on this endpoint, a missing or malformed marketId, interval, accountAddress, types or afterReportNo, a symbol on a market stream, or an interval the service doesn't publish |
-20008 | Unknown market id |
-20003 | The market catalog can't be read. Retry with backoff |
-20005 | This connection already holds the most subscriptions it may. Unsubscribe one first |
To subscribe to several streams, send several atlas.subscribe requests. You can send them back to back without waiting for each response.
atlas.unsubscribe
atlas.unsubscribeWebSocket/market/ws, /account/wssubscriptionIdSubscriptionIdrequired- The subscription to cancel.
atlas.unsubscribeWebSocketconst ws = new WebSocket("wss://<ws-host>/market/ws");
ws.onopen = () => ws.send(JSON.stringify({
"jsonrpc": "2.0",
"id": 1,
"method": "atlas.unsubscribe",
"params": {
"subscriptionId": "sub_7f3a"
}
}));
ws.onmessage = (ev) => {
const msg = JSON.parse(ev.data);
if (msg.id === 1) console.log(msg.result ?? msg.error);
};Press Send to see the response.After the success response, no more events arrive for that subscriptionId. An unknown id returns -20004.
Account streams and sign-in
Account streams need no sign-in. To sign a connection in anyway, see Sign in to a WebSocket.
Every event
Each notification's params object always carries these three fields, plus the stream's payload.
Every notification
subscriptionIdSubscriptionIdrequired- Which subscription this belongs to.
seqSeqStringrequired- Per-subscription counter as a decimal string. First event is
"1". snapshotbooleanrequiredtrue: full state, replace what you have.false: an update.
Times inside payloads (timestamp, T, createdAt and so on) are JSON integers of Unix milliseconds. Prices, sizes and amounts are decimal strings.
Sequence and snapshots
Every subscription starts with a response carrying its subscriptionId, then a snapshot at seq "1" (except an account stream you resume, and mark_price before its first tick), then updates. The session under Recovering from a gap shows each frame.
- Track
seqseparately for each subscription, and compare it as an integer. - When
snapshotistrue, replace your local state for that subscription. The server may send another snapshot later. Treat each one the same way. - When
snapshotisfalse, apply it as an update according to the stream's rules below.
Recovering from a gap
If seq skips, repeats or goes backwards, your state for that subscription is wrong. Waiting for the next snapshot is not enough.
Discard
Throw away local state for that subscription. On an account stream, keep the lastreportNoyou applied.Unsubscribe
Sendatlas.unsubscribefor the old id, if the connection is still up.Subscribe again
Send a freshatlas.subscribe. You get a newsubscriptionIdandseqrestarts at"1". On an account stream, passafterReportNoto resume instead of starting over.Rebuild
Rebuild from the new snapshot, or apply the resumed reports.
If the connection closes, every subscription on it is gone. Reconnect and subscribe again.
Play the session below, then try both failure modes. A gap costs you one subscription; a dropped connection costs you all of them.
- + 0ms●connection open
type Sub = { stream: string; marketId?: number; interval?: string; accountAddress?: string };
const ws = new WebSocket("wss://<ws-host>/market/ws");
let nextId = 1;
const pending = new Map<number, Sub>(); // request id -> subscribe params
const lastSeq = new Map<string, bigint>(); // subscriptionId -> last seq
const subs = new Map<string, Sub>(); // subscriptionId -> params
function subscribe(params: Sub) {
const id = nextId++;
pending.set(id, params);
ws.send(JSON.stringify({ jsonrpc: "2.0", id, method: "atlas.subscribe", params }));
}
function resubscribe(subId: string) {
const params = subs.get(subId)!;
subs.delete(subId);
lastSeq.delete(subId);
ws.send(JSON.stringify({ jsonrpc: "2.0", id: nextId++, method: "atlas.unsubscribe", params: { subscriptionId: subId } }));
subscribe(params);
}
ws.onopen = () => subscribe({ stream: "order_book", marketId: 4294967297 });
ws.onmessage = (ev) => {
const msg = JSON.parse(ev.data);
if ("id" in msg) { // a response
const params = pending.get(msg.id);
if (params && msg.result) subs.set(msg.result.subscriptionId, params);
pending.delete(msg.id);
return;
}
const { subscriptionId, seq, snapshot } = msg.params;
if (msg.method === "stream.closed") { // server ended it
subs.delete(subscriptionId);
return;
}
const n = BigInt(seq); // compare as integers, not strings
const prev = lastSeq.get(subscriptionId);
if (prev !== undefined && n !== prev + 1n) return resubscribe(subscriptionId);
lastSeq.set(subscriptionId, n);
if (snapshot) {
// replace local state with msg.params.data
} else {
// apply msg.params.data as an update (see each stream's rules)
}
};Market streams
stream.trades
Public trades for one market.
- First event (
snapshot: true): the most recent trades, up to 50, newest first. Replace your cached tape. - Then (
snapshot: false):dataholds one new trade. - A later snapshot means the server resynced and trades may have been missed. Treat it as replacement state: replace your tape with it, don't append it. It is not a replay of everything you missed; read
atlas.getTradesto fill a gap. - Payload:
Trade[]. Seeatlas.getTrades.liquidation: truemarks a liquidation's trade, so filtering on it gives a venue-wide liquidation feed.
{
"jsonrpc": "2.0",
"method": "stream.trades",
"params": {
"subscriptionId": "sub_19c2",
"seq": "214",
"snapshot": false,
"data": [{ "marketId": 4294967297, "symbol": "BTCUSDT-PERP", "price": "70150", "size": "0.05", "side": "buy", "timestamp": 1791210612345, "tradeId": "core:1335088:11" }]
}
}stream.order_book
The book for one market: one snapshot, then incremental updates. Levels are [price, size] pairs of decimal strings, best first.
- First event (
snapshot: true): up to 500 levels per side, and theupdateIdof the book state it shows. - Then (
snapshot: false): a delta for eachintervalin which the book changed. It holds only the levels that changed, each at its new absolute size. Size"0"removes the level. - The server may send a new snapshot at any time. Apply it like the first one.
OrderBookUpdate
marketIdintegerrequired- The market's id.
symbolSymbolrequired- The market's display symbol.
updateIdUint64Stringrequired- The book state this frame brings you to. Update ids increase but are not contiguous.
prevUpdateIdUint64String- Deltas only: the
updateIdof the previous delta for this market and interval. bidsPriceLevel[]required[price, size], best (highest) first. On a delta, only the changed levels.asksPriceLevel[]required[price, size], best (lowest) first. On a delta, only the changed levels.timestampTimestampMsrequired- When the book reached the state after this update.
To merge, keep a book keyed by price and the updateId it shows:
On a snapshot
Replace the whole book and take itsupdateId.On a delta, check it
If itsupdateIdis not above your book's, skip it. If itsprevUpdateIdis above your book'supdateId, a delta is missing: resubscribe.Apply it
Otherwise (prevUpdateId≤ yourupdateId< itsupdateId), set each listed level to its size, remove the levels whose size is"0", and take the delta'supdateId.
The first delta's prevUpdateId can be below the snapshot's updateId, as in the example; it still applies, because sizes are absolute. A delta can name levels deeper than the snapshot's 500 per side, so a deep level appears only once it changes. Trim your book to the depth you display.
type Level = [string, string];
type Book = { updateId: bigint; bids: Map<string, string>; asks: Map<string, string> };
let book: Book | undefined;
function onOrderBook(params: { snapshot: boolean; data: { updateId: string; prevUpdateId?: string; bids: Level[]; asks: Level[] } }) {
const { snapshot, data } = params;
const id = BigInt(data.updateId);
if (snapshot) {
book = { updateId: id, bids: new Map(data.bids), asks: new Map(data.asks) };
return;
}
if (!book || id <= book.updateId) return; // stale: skip
if (BigInt(data.prevUpdateId!) > book.updateId) return resync(); // a delta is missing
for (const [side, levels] of [[book.bids, data.bids], [book.asks, data.asks]] as const) {
for (const [price, size] of levels) {
if (/^0(\.0+)?$/.test(size)) side.delete(price); else side.set(price, size);
}
}
book.updateId = id;
}
function resync() { book = undefined; /* unsubscribe and subscribe again */ }The sketch keys levels by the price string as sent. If you mix in prices from elsewhere, normalize them to one form first (for example the market's priceScale decimals) so "70200" and "70200.0" hit the same level. Sort by numeric value when you render.
{
"jsonrpc": "2.0",
"method": "stream.order_book",
"params": {
"subscriptionId": "sub_7f3a",
"seq": "2",
"snapshot": false,
"data": {
"marketId": 4294967297,
"symbol": "BTCUSDT-PERP",
"prevUpdateId": "1361390",
"updateId": "1362215",
"bids": [],
"asks": [["70200", "0"], ["70400", "1.2"]],
"timestamp": 1791210612480
}
}
}This delta removes the 70,200 ask and sets 1.2 at 70,400. For a one-off snapshot over HTTP, use atlas.getOrderBook, which returns levels as { price, size } objects.
stream.candles
Candles for one market and interval. Payload: Candle[], the same shape as atlas.getCandles.
- First event (
snapshot: true): recent history. Each candle'sxsays whether it is final. - Then (
snapshot: false): one candle, either the live one updating (x: false) or a window closing (x: true). - Upsert by
t. A later frame for the sametreplaces the earlier one, even afterx: true. - An interval with no trades has no candle, so the next
tcan skip ahead. The closing frame can arrive a moment afterT.
{
"jsonrpc": "2.0",
"method": "stream.candles",
"params": {
"subscriptionId": "sub_c41d",
"seq": "88",
"snapshot": false,
"data": [{ "marketId": 4294967297, "t": 1791210000000, "T": 1791210060000, "s": "BTCUSDT-PERP", "i": "1m", "o": "70120", "h": "70160", "l": "70100", "c": "70150", "v": "2.315", "n": 41, "x": false }]
}
}stream.ticker
Payload: Ticker, the same shape as atlas.getTicker: top of book, last trade, the full rolling 24-hour window (including tradeCount24h, the number of trades in it), mode, mark and index price, and for perps funding, impact prices and open interest. Every frame carries the full ticker, so replace your cached ticker each time. A frame is pushed when the ticker changes.
stream.bbo
Payload: BBO (marketId, s, b, B, a, A, T), the same shape as atlas.getBBO. Sent when the top of book changes. Every frame is the full current BBO, so replace your cached value each time. Like the ticker, it is a latest-state stream: if you fall behind, the server may skip intermediate values and send only the latest. A side with no orders reads "0". For every price level, use stream.order_book.
stream.mark_price
Perps only. A light bundle of the mark price, index price and funding, restated periodically. No book or 24h stats. A spot pair's mark is on its ticker.
- First event (
snapshot: true): the latest tick, if one exists. If none has been produced yet, no snapshot is sent. - Then (
snapshot: false): one event per tick.
stream.mark_price params
subscriptionIdSubscriptionIdrequired- Your subscription.
seqSeqStringrequired- Per-subscription counter.
snapshotbooleanrequiredtrueon the first event only.dataMarkPricerequiredThe tick.
›Show 7 child fieldsHide child fields
marketIdintegerrequired- The perp's id.
symbolSymbolrequired- The perp's display symbol.
markPricePricerequired- Mark price, decimal string.
indexPricePrice | nullrequired- The latest index price, for display.
nulluntil the market has had one. fundingRateDecimalString- The current funding rate for the open session, as a signed decimal fraction:
"0.0001"is 1 bp. Positive means longs pay shorts. It can change until the session closes. Omitted until the market has a rate; a zero rate is"0". nextFundingTimeTimestampMs- When the open funding session is due to close, Unix ms. It can briefly be in the past. Omitted when none is scheduled.
timestampTimestampMsrequired- When this state was set, Unix ms. A restatement keeps the same time.
{
"jsonrpc": "2.0",
"method": "stream.mark_price",
"params": {
"subscriptionId": "sub_e902",
"seq": "3",
"snapshot": false,
"data": { "marketId": 4294967297, "symbol": "BTCUSDT-PERP", "markPrice": "70148.5", "indexPrice": "70139.2", "fundingRate": "0.0001", "nextFundingTime": 1791212400000, "timestamp": 1791210612000 }
}
}fundingRate is a decimal fraction here, on stream.account payment reports and on atlas.getFundingHistory. atlas.getFundingRateHistory still reports rateBps in basis points.
indexPrice here is for display only.
Account streams
stream.orders and stream.account deliver an account's reports in order, each one numbered. A subscription starts with a snapshot of the current state, then sends every report after it. If you disconnect, subscribe again with the last report number you hold and the stream picks up after it.
| Stream | Reports | Snapshot |
|---|---|---|
orders | order, fill | Every open order of the account, in openOrders |
account | balance, position, payment, walletState, accountReport | The account state, as atlas.getAccountState returns it, in account |
Every other frame arrives on both streams: snapshot, heartbeat, gapNotice and reject. Shapes inside a report are identical to what the matching HTTP read returns: atlas.getOpenOrders and atlas.getFills for orders and fills, atlas.getBalances and atlas.getPositions for balances and positions, atlas.getFundingHistory for payments.
Report numbers
Each report frame carries:
Report fields
reportNoUint64Stringrequired- The report's number on this stream for this account. The first is
"1"and each later one is one above the previous: never skipped, reused or reset."0"stands for no report yet. gkobjectrequired- The report's ordering position,
{ height, ordinal }:heighta decimal string,ordinalan integer. Positions rise strictly in stream order; compare them (heightfirst, thenordinal), don't interpret them. logTimeTimestampMsrequired- When the change the report shows happened, Unix ms.
txIdTxId- The signed transaction that produced the report. Absent when a system event produced it.
causeenum- Set instead of
txIdwhen a system event produced the report:advanceClock, the clock advance that books funding and expiries.
The two streams are numbered and ordered separately. Within stream.orders an order report and the fill it follows never arrive out of order, and within stream.account the same holds for a balance, a position and the reports around them. Nothing orders a frame of one stream against a frame of the other, so an order report and the balance it moves can arrive in either order. If you hold both subscriptions, don't join their frames by reportNo or gk.
Snapshots
A subscription without afterReportNo starts with a snapshot frame (snapshot: true). Replace what you hold for the account with it, then apply every report numbered above its reportNo.
snapshot data
typestringrequiredsnapshot.reportNoUint64Stringrequired- The snapshot covers every report of this stream up to and including this number. This is your resume point.
coveredThroughUint64Stringrequired- An opaque position the snapshot covers through, comparable with a heartbeat's
watermark. Not a resume cursor. openOrdersOrder[]- On
stream.orders: every open order of the account. accountAccountState- On
stream.account: the account state, asatlas.getAccountStatereturns it.
The server can also send a snapshot later, for example after a gapNotice, or on stream.account after a change no other report shows. A later snapshot is numbered like a report. Apply every snapshot the same way.
Resuming after a reconnect
Keep the highest reportNo you have applied, separately for each account and each stream. To resume, subscribe again with it as afterReportNo:
{ "jsonrpc": "2.0", "id": 7, "method": "atlas.subscribe", "params": { "stream": "orders", "accountAddress": "0x8f3a6c1e2b9d4f7a0c5e8b1d3f6a9c2e4b7d0f15", "afterReportNo": "1842" } }- Within reach: if the missing reports are still retained (currently about an hour), you get every report after
afterReportNo, once and in order, with no snapshot first. - Out of reach: otherwise the stream sends a
gapNoticenaming the reports it can't deliver, then a replacementsnapshot. Replace your state with it and continue from itsreportNo. - History unavailable: if the account's reports can't be read, the subscription is closed with
stream.closedand-20003(Service unavailable). Retry with backoff.
Report numbers belong to the stream, not to RPC paging: don't pass a reportNo as a history cursor, or a cursor as afterReportNo. atlas.getOpenOrders pagination is separate.
Filtering report types
Pass types to receive only some report types, for example ["fill"] on orders or ["balance", "payment"] on account. snapshot, gapNotice and heartbeat frames always arrive.
A filter doesn't renumber the stream: the reports you don't receive keep their numbers, so reportNo jumps. That jump is not a loss. Track progress with the heartbeat's scannedThrough instead, and resume from the higher of your last reportNo and the last scannedThrough.
Heartbeats, gaps and rejects
data.typetypestringrequiredheartbeat.watermarkUint64Stringrequired- An opaque position: every report of this stream for the account up to it has been delivered, filtered out or covered by a snapshot. Compare it with a snapshot's
coveredThrough; don't interpret it. logTimeTimestampMsrequired- The time at
watermark, Unix ms. scannedThroughUint64Stringrequired- The highest report number passed, filtered types included.
stream.orders
Order and fill reports for one account.
stream.orders params
subscriptionIdSubscriptionIdrequired- Your subscription.
seqSeqStringrequired- Per-subscription counter.
snapshotbooleanrequiredtrueonly on asnapshotframe.accountAddressAccountAddressrequired- The subscribed account.
dataobjectrequired- One frame, tagged on
type:order,fill, or a control frame.
Each report also carries the report fields: reportNo, gk, logTime, and txId or cause.
data.typetypestringrequiredorder.orderOrderrequired- The Order object, identical to what
atlas.getOpenOrdersandatlas.getOrderHistoryreturn. ItstxIdis the signed transaction that placed it.
{
"jsonrpc": "2.0",
"method": "stream.orders",
"params": {
"subscriptionId": "sub_a001",
"seq": "16",
"snapshot": false,
"accountAddress": "0x8f3a6c1e2b9d4f7a0c5e8b1d3f6a9c2e4b7d0f15",
"data": {
"type": "order",
"reportNo": "1843",
"gk": { "height": "40211873", "ordinal": 0 },
"logTime": 1791210612351,
"txId": "0x27ca64c092a959c7edc525ed45e845b1de6a7590d173fd2fad9133c8a779a1e3",
"order": { "orderId": "perp:1:48213", "accountAddress": "0x8f3a6c1e2b9d4f7a0c5e8b1d3f6a9c2e4b7d0f15", "clOrdId": "0x5f1c9a7e3b2d4c6e8a0b1d3f5e7c9a2b", "txId": "0x27ca64c092a959c7edc525ed45e845b1de6a7590d173fd2fad9133c8a779a1e3", "marketId": 4294967297, "seq": 48213, "side": "buy", "type": "limit", "price": "70300", "size": "1", "status": "partially_filled", "filledSize": "0.4", "remainingSize": "0.6", "trimmedSize": "0", "avgFillPrice": "70220", "marginMode": "cross", "createdAt": 1791210612345, "updatedAt": 1791210612351, "signerRole": "agent" }
}
}
}Orders and fills carry marketId, not a symbol: resolve the display symbol from atlas.getSymbols.
- Orders: to tie an order report back to your write, match
order.txIdto thetxIdyouratlas.sendRawTransactionresult carried. A transaction carries one command, so itstxIdidentifies it. The report frame's owntxIdnames the transaction that produced that report, so a cancel's report carries the cancel'stxIdwhileorder.txIdstays the one that placed the order. - Fills: match a fill to your order by
orderId. A fill'stxIdis the transaction that produced the trade: your own write on a taker fill, the other side's when your resting order is hit.
Orders and fills no client-signed transaction caused, such as a liquidation's fills or an order placed for a TP/SL or TWAP, carry no txId.
stream.account
Balance, position, payment, wallet-state and account reports for one account.
stream.account params
subscriptionIdSubscriptionIdrequired- Your subscription.
seqSeqStringrequired- Per-subscription counter.
snapshotbooleanrequiredtrueonly on asnapshotframe.accountAddressAccountAddressrequired- The subscribed account.
dataobjectrequired- One frame, tagged on
type: a report below, or a control frame.
A balance or position report shows the state after the change and names the transaction that last changed it. Every report also carries the report fields; the examples below include them once.
data.typetypestringrequiredbalance.balanceBalancerequiredA Balance row: one asset in one place.
›Show 8 child fieldsHide child fields
placeenumrequiredstaked,crossorisolated.symbolSymbol- On an
isolatedrow: the unit's market. assetstringrequired- Asset symbol, for example
USDT. assetIdintegerrequired- Asset id.
totalDecimalStringrequired- Ledger balance, exact to 12 decimal places.
availableDecimalStringrequiredtotallessheld.heldDecimalStringrequired- Reserved for resting spot orders and pending withdrawals; on a
stakedrow, the pending unstake. unstakeDueNsUint64String- On a
stakedrow with a pending unstake: when it returns to the cross unit, Unix nanoseconds.
{
"jsonrpc": "2.0",
"method": "stream.account",
"params": {
"subscriptionId": "sub_a002",
"seq": "4",
"snapshot": false,
"accountAddress": "0x8f3a6c1e2b9d4f7a0c5e8b1d3f6a9c2e4b7d0f15",
"data": {
"type": "balance",
"reportNo": "903",
"gk": { "height": "40211873", "ordinal": 0 },
"logTime": 1791210612351,
"txId": "0x27ca64c092a959c7edc525ed45e845b1de6a7590d173fd2fad9133c8a779a1e3",
"balance": { "place": "cross", "asset": "USDT", "assetId": 1, "total": "25000", "available": "24850", "held": "150" }
}
}
}Values in these examples are illustrative.
When the server ends a stream
stream.closed
The server can end a subscription while keeping the connection open. It always sends stream.closed first, and that is the last message for that subscriptionId.
stream.closed params
subscriptionIdSubscriptionIdrequired- The subscription that ended.
seqSeqStringrequired- Continues the subscription's sequence.
snapshotbooleanrequired- Always
false. reasonCodeErrorCode (integer)required- Why it ended.
-20006means closed for backpressure. See Errors. messagestringrequired- Human-readable reason.
{
"jsonrpc": "2.0",
"method": "stream.closed",
"params": { "subscriptionId": "sub_7f3a", "seq": "42", "snapshot": false, "reasonCode": -20006, "message": "Slow consumer" }
}Mark the subscription closed. Resubscribe if you still want it. Treat unknown reasonCode values as normal, not as parse errors.
Slow consumers
If you read too slowly, ATLAS protects itself in two steps.
| Step | What happens | Signal |
|---|---|---|
| 1 | Expensive subscriptions are dropped | stream.closed with reasonCode: -20006 |
| 2 | If you are still too slow, the connection is closed | The WebSocket closes, with or without stream.closed (-20007) for each subscription first |
Don't rely on a close code or reason text. Treat the close itself as the signal: every subscription on that connection is gone. Reconnect with jittered exponential backoff, then subscribe again, resuming account streams from their last reportNo.
Heartbeats
Liveness uses standard WebSocket ping and pong frames. The server pings; most WebSocket libraries answer automatically. On /market/ws and /account/ws, a connection that stops answering pings is closed. Reconnect and subscribe again.