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 message exchange without the overhead of HTTP polling. 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 are wrapped within a top-level client or server message envelope. This structure ensures extensibility and consistency across different message types.
Example Envelope: ``` message ClientMessage {
oneof payload { SubscribeRequest subscribe = 1; OrderRequest order = 2; }
}
message ServerMessage {
oneof payload { MarketUpdate market_data = 1; OrderResponse order_response = 2; }
} ```
This design enables efficient message parsing while maintaining flexibility.
Next Steps
Continue to the [Connecting and Authenticating](developers:websocket:connecting) section to learn how to establish a WebSocket connection and authenticate your session.