Stage 2: Websocket Management
Websocket connections are essential for real-time data streaming and order management in the Tradovate API. This stage validates your integration’s ability to maintain stable websocket connections and handle real-time events.
Overview
The websocket management stage ensures your application can:
- Establish and maintain websocket connections
- Handle authentication over websocket
- Process real-time events and maintain idempotency
- Manage connection heartbeats and reconnection logic
- Handle rate limiting and synchronous requests
Required Tests
1. Websocket Login
Purpose: Authenticate websocket connection using access token.
Test Steps:
- Establish websocket connection to
wss://demo.tradovateapi.com/v1/websocket - Send authentication message with valid access token
- Verify successful authentication response
- Test with invalid/expired token to ensure proper error handling
Example Implementation:
Expected Authentication Response:
Expected Error Response:
Validation Criteria:
- ✅ Websocket connection establishes successfully
- ✅ Authentication succeeds with valid token
- ✅ Authentication fails with invalid token
- ✅ Connection remains stable after authentication
2. Heartbeats
Purpose: Maintain connection health and detect disconnections.
Test Steps:
- Send periodic heartbeat messages
- Verify heartbeat responses are received
- Test heartbeat timeout scenarios
- Verify connection recovery after missed heartbeats
Example Implementation:
Validation Criteria:
- ✅ Heartbeats are sent at regular intervals
- ✅ Heartbeat mechanism works during high message volume
3. Event Handling
Purpose: Process real-time events from the websocket.
Test Steps:
- Manage real-time subscriptions
- Start event streaming using
user/syncrequest - subscribe to relevant entity types using the
entityTypesparameter
- Start event streaming using
- Process incoming events and maintain Idempotency
Example user/syncrequest:
Validation Criteria:
- ✅ Only one
syncrequestis sent per socket lifecycle. - ✅ Real-time events are received
- ✅ Idempotency is maintained
- ✅ Sharding is implemented correctly
- ✅ Entity types are subscribed to correctly
- ✅ Syncrequest is sent correctly
- ✅ Event handlers are robust and don’t crash on malformed data
- ✅ Message processing performance meets requirements
4. Rate Limit Handling (P-Ticket)
Purpose: Handle rate limiting and priority ticket system.
Test Steps:
- Send requests that trigger rate limiting
- Verify P-Ticket system responses
- Implement proper queuing and retry logic
- Test priority handling for different request types
Example Implementation:
Validation Criteria:
- ✅ Rate limiting responses are properly handled
- ✅ P-Ticket system is implemented correctly
5. Reconnection
Purpose: Automatically reconnect after connection loss.
Test Steps:
- Simulate connection drops
- Verify automatic reconnection logic
- Test re-authentication after reconnection
- Verify state recovery after reconnection
Example Implementation:
Validation Criteria:
- ✅ Automatic reconnection works after connection loss
- ✅ Re-authentication occurs after reconnection
- ✅ State is properly recovered after reconnection
Error Handling
Your websocket implementation must handle:
Connection Errors
- Network timeouts
- DNS resolution failures
- SSL/TLS handshake failures
- Server unavailable errors
Authentication Errors
- Invalid access tokens
- Expired tokens during connection
- Authentication timeout
Message Errors
- Malformed JSON messages
- Unknown message types
- Invalid message parameters
Performance Requirements
- Connection Time: Establish connection within 5 seconds
- Authentication: Complete authentication within 2 seconds
- Heartbeat: Send heartbeats every 30 seconds
- Reconnection: Attempt reconnection within 10 seconds of disconnection
- Message Processing: Process messages within 100ms
Testing Checklist
- Websocket connection establishes successfully
- Authentication works with valid tokens
- Heartbeats are sent and received
- Events are processed correctly
- Idempotency is maintained
- Rate limiting is handled properly
- Syncrequests work as expected and are called only once per socket lifecycle
- Reconnection works automatically
- Error handling is robust
Next Steps
After completing Stage 2 websocket management tests, proceed to Stage 3: User Management.

