Skip to main content
StreamAccountEvents · read key One long-lived connection that sends the state of every account the key reaches, then each change as it happens: orders, cancels, fills, balance and positions. It replaces polling GetAccountSnapshot, ListOpenOrders and ListTrades. Demo accounts are not on the stream. A reader that follows this page, in Python and in Node.js, is in hypernova-core/hypernova-api.
Enabled per user during the pilot. If a connect ends with permission_denied and the kind EVENT_STREAM_DISABLED, your key is fine and the stream is not turned on for you yet. Ask us in the Hypernova Discord.

The connection

This is the one endpoint that is not a plain JSON call: the request, and every message of the response, is a frame.
A frame is five bytes followed by a JSON object:
  • The request is a single frame with flag 0. Its JSON is {} on a first connect, or {"resumeToken":"…"} with the token you last saved from ready.
  • The response answers HTTP 200, then sends frames for as long as the stream is open. Flag 0 is an event. Flag 2 is the last frame: {} when the stream ended normally, or an error when it did not.
  • A request with any other content type answers HTTP 415 and no frame. A compressed request, and a request field the endpoint does not define, are refused in the last frame, as unimplemented and invalid_argument.
To watch a stream from a terminal, in bash or zsh:
curl prints each frame as it arrives, header bytes included, so it shows you the stream but is not a client. --output - is needed because the frames are binary, and curl otherwise refuses to print them to a terminal. A connect that the stream itself refuses, as for a bad key, still answers HTTP 200, with one last frame:

Events

Every event is a JSON object with exactly one of the members below, and an accountId beside it unless the event concerns the whole connection. The JSON of successive frames on a first connect, with nested objects shortened to { … }:
  • Balance and positions are sampled, so they can lag a fill: a position can still show its old size just after the trade that closed it.
  • A live order or trade event can be missing or repeated, and the kinds are not ordered against each other: a fill can arrive before its order update.
  • Two OPEN updates for one order can arrive in either order. When they conflict, read ListOpenOrders before acting on either.
  • ListOrderHistory settles an order whose final update never came. It can list an order as FILLED while the fill is still being booked, and that row can still turn REJECTED or CANCELLED, so confirm an execution with a trade that carries the same orderId.

How a connection starts

A connection always begins the same way:
  1. One account event for every account the key reaches.
  2. balance, positions and openOrders for each account that is active or suspended. Any other account, such as one that has passed or failed, sends no snapshot, but step 3 still replays its fills, its closing trade included, so keep reading its trade events.
  3. Any fills recorded since the token in the request, as trade events.
  4. ready.
Hold everything before ready aside and apply it together when ready arrives. If the connection ends before ready, discard what you held and keep your previous state, marked stale. After ready the stream is live. order, orderCancelled and trade are sent as they happen. balance and positions are checked once a second and sent only when they changed, so an account with no open position is silent apart from heartbeats. Live events are sent only for the accounts that were active or suspended when the connection opened.

Resuming

ready tells you how to continue:
  • Save resumeToken once you have applied the snapshot, and send it on your next connect. The fills recorded since then are replayed before that connection’s ready.
  • tradesComplete is true when the replay covered every recorded fill since your token. It is false on a first connect, when the token is more than an hour old, when more than 1,000 fills were recorded since it, or when trade history could not be read in time. When it is false, page ListTrades for each account before you save the token.
  • A replay reaches back a minute past your token on purpose, so a fill can arrive twice. Keep only the first copy of each tradeId.

Reconnecting

A stream does not stay open indefinitely, so a client is a loop:
  • We end every stream after five to six minutes, with a last frame of {}. Reconnect at once with your saved token.
  • A stream can also stop with no last frame, for example during a deploy on our side. Treat it the same way.
  • If nothing arrives for 45 seconds, not even a heartbeat, treat the connection as dead and reconnect.
  • On an error in the last frame, act on its code as below.

Stream errors

Check the HTTP status before you decode any frame. A connect refused before the stream starts answers a status other than 200 with a body that is not a frame: 415 with a plain-text body for a content type other than application/connect+json, and the edge’s 429 and 403 from Refusals that carry no error body. A reader that feeds such a body to its frame decoder loses the actual error. On a stream that answered 200, an error arrives in the last frame, never as the HTTP status. The frame’s metadata holds what a plain call would send as response headers, each as a list of strings: the kind in X-Hn-Error-Kind, and Retry-After where the table says so. Match those names without regard to case. Events cost nothing against any limit, and opening a stream draws on a budget of its own, given under Rate limits. A client that stops without closing its connection can hold its place under the stream cap until that stream’s five to six minutes are up.