Skip to main content

Connecting

Each stream is a separate WebSocket connection at its own path; there is no subscribe/unsubscribe message protocol. Authenticated Trading API streams use the same identity as REST (details): use Authorization: Bearer <token> and User-Id headers when your client can set them. Browser clients can pass Bearer-<token>, User-<id> as Sec-WebSocket-Protocol values. Trading API streams support two message protocols:
  • v0 (default): raw JSON payloads.
  • v1: include tplus.ws.v1 in Sec-WebSocket-Protocol. Messages arrive in envelopes:
On v0 the payload is the bare event object, with no envelope. A trade-events (/trades/user/events/{user_id}) message, for example:
That same object is the data field under v1. For authenticated browser clients, Bearer-<token>, User-<id>, and tplus.ws.v1 can appear in the Sec-WebSocket-Protocol list. The Trading API auth parser reads the bearer token and user from any position in the list, and enables v1 if tplus.ws.v1 is present. When auth succeeds through that header, the server echoes the first offered value as the selected subprotocol; put tplus.ws.v1 first when you want the browser connection to report v1 as selected. Market Data API streams currently use raw v0 frames only: a WsWelcome text frame first, then raw payloads. Do not expect v1 envelopes from those services. After the welcome frame, the listed OMS and MDS streams run through a shared WebSocket stream loop. That loop sends a WebSocket ping every 20 seconds and responds to WebSocket ping frames with pong frames. For one-way stream connections, a text message {"type":"ping"} can receive {"type":"pong"}. Do not use that text message as the /control heartbeat: /control parses text frames as order commands, and invalid v1 command envelopes can be rejected before app-level ping handling. The service code does not define an application-level idle timeout or a per-user/global WebSocket connection cap. Any idle close or connection cap is enforced outside the service, such as at a reverse proxy or load balancer.

Trading API streams (authenticated)

Settler approval delivery uses a dedicated WebSocket outside the Trading API surface (/settlement/approvals/{settler_pubkey}, encrypted to the settler’s key); see Settlement.

Market Data API streams (public)

Indicative funding and borrow rates also stream publicly from the interest engine’s /rates endpoint, a separate service from the two documented APIs; see Fees & rates. Message schemas are in the live Trading API and Market Data API references.

Lag and resync

Trading API streams close with code 1013 and reason resync_required when the client falls behind. On v1, the server sends a RESYNC_REQUIRED error before closing. Market Data API streams do not support v1 envelopes; if their broadcast receiver lags, the raw stream handler terminates the connection without a resync message.