This is an old revision of the document!
WebSocket API Introduction
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
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
Google Protocol Buffers (Protobuf)
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
Communication Model
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)
Message Structure Overview
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.
A C# helper tool is available to streamline message handling. It is part of a repository that provides free utilities for developers. [Repository Placeholder - Add Link]
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 fields in a ClientMessage:
- AuthenticationRequest
- MarketSubscription
- OrderRequest
- … (and other client-initiated 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 fields in a ServerMessage:
- AuthenticationResponse
- MarketSnapshot
- OrderUpdate
- … (and other server-generated messages)
Each message type within these envelopes is a Protobuf message, allowing for efficient serialization and deserialization. Developers should extract the relevant fields based on their needs.