Connection endpoint
Connect to the WebSocket server using the following endpoint:WS_STREAM_URL environment variable on the server.
Connection process
Establish WebSocket connection
Open a WebSocket connection to the endpoint. The server accepts standard WebSocket handshake requests.
Send subscription messages
After connecting, send subscription requests to start receiving market data. See the Subscriptions page for details.
Message format
Client messages
All messages sent from the client to the server must be JSON objects with the following structure:| Field | Type | Description |
|---|---|---|
method | string | The action to perform: SUBSCRIBE or UNSUBSCRIBE |
params | array | Array of stream identifiers to subscribe/unsubscribe |
id | number | Request identifier for tracking |
Server messages
The server sends updates as JSON objects with this structure:| Field | Type | Description |
|---|---|---|
stream | string | The stream identifier this data belongs to |
data | object | The actual market data (format varies by stream type) |
Connection management
Closing connections
To gracefully close the connection, send a WebSocket close frame. The server will:- Remove you from all subscriptions
- Clean up your user session
- Acknowledge the close
Error handling
The server handles various error scenarios:Protocol errors: Invalid WebSocket frames will log a protocol error and close the connection.
Connection errors: Network issues or unexpected disconnections will trigger automatic cleanup of your subscriptions.
Invalid messages: Non-JSON or improperly formatted messages are silently ignored. Ensure your messages match the expected format.
Reconnection strategy
If your connection drops, implement a reconnection strategy:Architecture notes
The WebSocket server:- Uses Redis Pub/Sub for distributing market data updates
- Maintains user subscriptions in memory for fast routing
- Automatically unsubscribes from Redis channels when no users are listening
- Identifies users by their connection address
- Supports multiple concurrent connections
Next steps
Subscriptions
Learn about available data streams and how to subscribe
REST API
Explore the REST API for account management and trading