Skip to content
Cirrus home
Sign in

Reference

Live stream

One WebSocket with your orders and portfolio as they change.

Read the guide first

Live updates (WebSocket) #

GET /v1/stream scope read

Upgrades to a WebSocket carrying the user's live order and portfolio state and new activity-log records, as JSON text frames.

More about this

Client messages are StreamClientMessage, server messages StreamServerMessage (see x-websocket-messages).

**Authentication.** Either send the credential on the upgrade request (an Authorization header, as on every route), or send as the first message {"type":"auth","token":"..."} within 5 s of connecting. Credentials are never read from the URL. The credential needs the read scope. A failed check does not answer 401/403: the upgrade succeeds and the socket is closed with code 4001. The credential is re-checked every 10 s; logout or revocation closes the stream (4001).

**Messages.** Every server message has a per-connection seq (1, 2, 3, ...). First hello (user and accounts), then one snapshot per account and data kind (orders always, an empty list when there are none; other kinds when there is data), or for an account with no live data (no broker session, or its session expired; broker not supported) one missing message with the same code / reason as REST missing; then snapshot_done; after that live order_update, portfolio and activity messages. Every event carries full state (the whole order, the whole kind), never a diff, so a missed message is repaired by the next one for the same order or kind. After a gap in seq, send {"type":"resync"} to get every snapshot again (then snapshot_done). If live updates cannot be set up an error message (unavailable) is sent and the stream ends: reconnect.

**Heartbeat.** The server pings every 15 s and closes a connection it has heard nothing from for 45 s (code 1000).

**Close codes.** 4001: credential missing, invalid, expired, revoked or without the read scope (or the first message was not auth); 4002: no auth message within 5 s; 1013: the client fell too far behind (reconnect for a fresh snapshot); 1001: server shutting down; 1000: idle.

Errors

HTTPCodeWhen
400—

Not a valid WebSocket upgrade (missing or wrong Connection, Upgrade, Sec-WebSocket-Version or Sec-WebSocket-Key header): plain text.

426—

Upgrade Required: the connection cannot be upgraded (e.g. an HTTP/1.0 or proxied connection that drops the upgrade); plain text.

A WebSocket: see the live stream guide for how to connect and the messages it sends.