developers:websocket

The WebSocket API provides a high-performance, low-latency communication channel for real-time trading data and order execution. This section introduces the key technologies used in the API: WebSockets and Google Protocol Buffers (Protobuf).

WebSockets establish a persistent, full-duplex connection between the client and server, allowing for continuous bi-directional message exchange. This ensures minimal latency, making it ideal for market data feeds and order updates.

Key Advantages:

  • Persistent connection reduces handshake overhead
  • Low-latency, real-time data exchange
  • Efficient bandwidth usage compared to REST APIs

The API utilizes Protobuf for efficient, compact, and high-speed message serialization. Unlike JSON or XML, Protobuf messages are smaller and faster to parse, making them well-suited for high-frequency trading applications.

Why Protobuf?

  • Compact Encoding: Reduces message size for faster transmission
  • High Performance: Faster serialization/deserialization than JSON
  • Schema Evolution: Backward-compatible changes allow for future expansion without breaking existing clients

The API follows a structured messaging approach:

  • Client Messages: Requests sent from clients to the server (e.g., order submission, subscription requests)
  • Server Messages: Responses and real-time updates sent from the server (e.g., trade confirmations, market data)

All messages sent to the server must be wrapped in a ClientMessage envelope, and all messages received from the server will be contained within a ServerMessage envelope. This ensures a consistent structure and simplifies message parsing.

Client Message Structure

A ClientMessage is the top-level wrapper for all messages sent to the server. It contains fields for various message types, such as authentication requests, order submissions, and subscription requests.

Example ClientMessage:

message ClientMessage {
  oneof payload {
    AuthenticationRequest authentication_request = 1;
    MarketSubscription market_subscription = 2;
    OrderRequest order_request = 3;
    // ... other client messages
  }
}

Server Message Structure

A ServerMessage is the top-level wrapper for all responses and updates from the server. It encapsulates messages related to market data, account updates, and execution reports.

Example ServerMessage:

message ServerMessage {
  oneof payload {
    AuthenticationResponse authentication_response = 1;
    MarketSnapshot market_snapshot = 2;
    OrderUpdate order_update = 3;
    // ... other server messages
  }
}

Message Tools

The T4 API Tools repository has code that makes wrapping messages from your client very easy.

Note: Reach out to support if you would like a API tool's for a language we have not covered yet.

Platform Client Message Helper
.Net ClientMessageHelper.cs
  • developers/websocket.txt
  • Last modified: 2025/03/14 19:15
  • by chad