Tektii just went live. We're shipping fixes daily — spot a bug? Let us know

WebSocket Messages

The Trading API uses WebSocket connections for real-time event streaming. This page documents the protocol mechanics: the message envelope, the messages your strategy sends, and the server heartbeat. Payloads for every server→client event live in the Event Types reference.

Message Format

All messages use JSON with an internally-tagged format. The type field identifies the message type:

{"type": "ping", "timestamp": "2025-01-15T10:30:00Z"}
{"type": "order", "event": "ORDER_FILLED", "order": {...}}

Client to Server Messages

Your strategy sends these messages to the Trading API.

Pong

Response to a server ping heartbeat. Send this to keep the connection alive.

{
  "type": "pong"
}

EventAck

Acknowledge processed events. Required in backtest mode — the engine stops advancing simulated time until an ACK arrives. Informational-only in paper and live modes. A single event_ack frame drains all of the Gateway's outstanding events at once (auto-correlation).

FieldTypeDescription
typestringAlways "event_ack"
correlation_idstringCaller-chosen ID (typically a UUID) useful for correlating ACKs in logs
events_processedstring[]Informational — the Gateway does not match entries to specific events; an empty array is fine
timestampintegerUnix timestamp (milliseconds) when the strategy finished processing
{
  "type": "event_ack",
  "correlation_id": "550e8400-e29b-41d4-a716-446655440000",
  "events_processed": ["evt_123", "evt_124"],
  "timestamp": 1700000000000
}

See Event Types → Event Acknowledgment for the full semantics and mode-dependent behavior.

Server to Client Messages

Ping

Server heartbeat. Respond with a pong message to keep the connection alive.

{
  "type": "ping",
  "timestamp": "2025-01-15T10:30:00Z"
}

Event Messages

Every other server→client message is an event, identified by its type field. Full schemas, enums, and JSON examples for each are in the Event Types reference:

typePayloadReference
orderOrder state changes — event (e.g. "event": "ORDER_FILLED") + orderOrder Events
positionPosition state changes — event + positionPosition Events
accountAccount balance / margin changes — event + accountAccount Events
tradeIndividual fills — event + tradeTrade Events
candleOHLCV bar — barCandle Event
quoteBid/ask/last update — quoteQuote Event
connectionGateway / upstream broker connection stateConnection Events
rate_limitRate limit warningsRate Limit Events
data_stalenessMarket-data freshness went STALE/FRESHData Staleness Events
errorError notificationsError Events

Event Subscription

Event subscriptions are configured at startup via environment variables, not through WebSocket messages. Configure the SUBSCRIPTIONS environment variable to specify which events your strategy receives. See Connection → Event Subscription for the schema.