Skip to main content

Connecting

Each stream is a separate WebSocket connection at its own path; there is no subscribe/unsubscribe message protocol. Authenticated OMS 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. OMS API streams support two message protocols:
  • v0 (default): raw JSON payloads.
  • v1: include tplus.ws.v1 in Sec-WebSocket-Protocol. Messages arrive in envelopes, except the bare {"type":"pong"} reply to an app ping:
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 OMS 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 either that header or the Authorization/User-Id headers, the server echoes tplus.ws.v1 as the selected subprotocol whenever it was offered, wherever it appears in the list. A v0 client that authenticates through the header without offering tplus.ws.v1 gets the first offered value echoed. Market Data Service 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. A text message {"type":"ping"} receives {"type":"pong"} on every stream, /control included. The shared stream loop does not define an application-level idle timeout. Additional idle-close policies can be enforced at a reverse proxy or load balancer. See Connections and streams for the connection caps and the errors returned at a cap. MDS has a single concurrent-connection cap shared by all six public WebSocket routes. The top-level MDS configuration setting max_public_ws_connections defaults to 1000 per instance and takes effect on restart, independently of REST rate limiting. At capacity, MDS refuses new upgrades with HTTP 503 (SERVICE_UNAVAILABLE, retryable); existing streams continue. A connection holds its slot until its stream ends, including error and lag termination. For example, with a cap of 2, two connections across any of these routes are accepted, a third is refused, and closing either connection allows a new one. Setting the cap to 0 refuses all public WebSocket upgrades. These market-data streams remain public and unauthenticated. The cap bounds their total count inside each MDS process; per-IP and volumetric connection limits remain the edge’s responsibility. Operators should size the cap for instance resources and expected subscribers and coordinate it with the edge connection limit.

OMS API streams (authenticated)

/control replies

On v1, send each request as {"request_id": "req_1", "data": {...}}. Every reply to it carries the same request_id and has one of three type values:
  • ack: the request was accepted. data is {"request": {"status": "submitted"}}. Order requests, batches, bulk cancels, clear-position requests and intent signals are all acknowledged this way.
  • event: an outcome that arrives later. Each order gets its own CreateOrderResponse, ReplaceOrderResponse, AmendOrderResponse or CancelOrderResponse, and a successful clear gets a ClearPositionResponse. An order the orderbook rejects is an event with a rejected status, not an error. A rejected event also carries the code and retryable that the same rejection gets over REST.
  • error: data is null and error is an error body with code, message, retryable and, for some codes, details. The error reply is sent for:
    • a request that does not parse (INVALID_REQUEST)
    • an invalid intent signal (INVALID_REQUEST)
    • a batch refused as a whole, before any item is processed. Over 50 items is BATCH_TOO_LARGE, and a repeated order id in a batch replace or batch amend is INVALID_REQUEST
    • a create, replace, amend or cancel the OMS could not send to the orderbook, for example while the market’s state is being recovered (INTERNAL_ERROR, retryable). The request was not applied, and no ack is sent for it. An item of a batch or an order of a bulk cancel that could not be sent gets a rejected event with reason InternalError (code INTERNAL_ERROR, retryable) instead
    • a request over the per-user or global rate limit (RATE_LIMITED, retryable, with details.retry_after_ms when the request can fit after a wait)
    • a failed authorization check, such as UNAUTHORIZED
    • a failed clear-position request: CE_REJECTED with the clearing engine’s reason in details.reason, TIMEOUT_UNKNOWN_STATE, or CE_COMMUNICATION_ERROR
    • SERVER_BUSY (retryable, with details.retry_after_ms), WARMING_UP, and MANAGED_BY_ANOTHER_OMS
On v0, replies are raw payloads with no type or request_id: an accepted intent signal is {"request": "submitted"}, a refused batch, or a request the OMS could not send to the orderbook, is {"request": {"status": "error", "error": "<reason>"}}, an invalid intent signal is {"error": "<reason>", "retryable": false}, and a rate-limited request carries retry_after_ms, for example {"error": "rate_limited", "retryable": true, "retry_after_ms": 4}. Both versions omit the wait when the request costs more than its bucket holds; split that request before retrying. Some v0 failures, including an unparseable request or one sent while the OMS is warming up, are dropped with no reply.

Market Data Service API streams (public)

A top-of-book frame contains asset_id, best_bid and best_ask as {"price":"25","size":"100"}, and the time the MDS built the frame in nanoseconds (timestamp_ns) and whole milliseconds (timestamp_ms). The initial frame is sent even when both sides are empty. It reads the depth just updated, independently of the ticker’s one-second cadence, and carries no staleness flag. The gateway may choose any MDS instance for this stream. It shares the public connection cap and the other per-market streams’ 404, 426, 503, lag and delisting behavior. Message schemas are in the live OMS API and Market Data Service API references.

Lag and resync

OMS 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 Service API streams do not support v1 envelopes; one that falls behind closes with code 1013 and reason resync_required, with no error message first. When a market is delisted, its streams close with code 1000 and reason market_delisted.