Skip to main content

Orders Channel

TL;DR

/ws/orders streams order-lifecycle events for your account: each time one of your orders changes state (partial fill, full fill, cancellation, expiry), the engine pushes an event. The stream is per-account: you only ever see your own orders. Use it instead of polling GET /orders/{id}.

Connect

wss://<gateway-host>/ws/orders?token=<access_token>

Self-authenticating with the bearer token as ?token= (the Authorization header is also accepted). The stream is per-account: events are routed to you by the order-id → account mapping the engine records at intake, so a subscriber only ever receives events for orders it placed.

Event shape

Each message is a JSON object describing one state transition:

{
"seq": 12,
"order_id": "aa00000000000000000000000000000001",
"kind": "partially_filled",
"filled_quantity": 3000000,
"new_amount": 7000000,
"new_note_amount": 1050000000
}
FieldTypePresent whenDescription
seqintegeralwaysPer-connection monotonic sequence, starting at 1. A gap means missed events.
order_idstringalwaysThe 16-byte order id, hex.
kindstringalwaysThe transition: partially_filled, fully_filled, cancelled, or expired.
filled_quantityintegeron fillsCumulative filled quantity.
new_amountintegeron partial fillThe residual base amount still resting.
new_note_amountintegeron partial fillThe residual collateral-note value after the fill re-locked the remainder.

Event kinds

kindTerminal?Meaning
partially_filledNoPart of the order filled; the remainder keeps resting (re-locked into a new note).
fully_filledYesThe order filled completely.
cancelledYesThe order was cancelled, whether by you, by a modify, or on session disconnect.
expiredYesThe order reached its expiry_slot without fully filling.

A terminal event is the order's last; after it, the order has left the book and produces no further events.

Event flow

A partial fill carries the residual size so you always know how much is still working; the matching fill memo (which note the change went into) arrives on the Fills Channel.

Gap recovery

Every event carries a per-connection monotonic seq (starting at 1). Track the last seq you processed; if the next event's seq is not exactly one greater, you missed events in between, so reconcile the orders you care about with GET /orders/{order_id}.

If a slow consumer falls behind the per-account buffer, the server also closes the socket with code 1011. On a 1011 close, reconnect and reconcile. The channel is a low-latency notifier, not a durable log.

Example

const ws = new WebSocket(`${WSS}/ws/orders?token=${TOKEN}`);

ws.onmessage = (e) => {
const ev = JSON.parse(e.data);
switch (ev.kind) {
case "partially_filled":
console.log(`partial: ${ev.filled_quantity} filled, ${ev.new_amount} resting`);
break;
case "fully_filled":
console.log(`filled: ${ev.order_id}`);
break;
case "cancelled":
case "expired":
console.log(`${ev.kind}: ${ev.order_id}`);
break;
}
};

ws.onclose = (e) => {
if (e.code === 1011) reconnectAndReconcile();
};