Stage 5: Market Data
Market data access is essential for trading applications. This stage validates your integration’s ability to establish WebSocket connections, subscribe to real-time market data, and handle market data streams effectively.
Overview
The market data stage ensures your application can:
- Establish secure WebSocket connections for market data
- Subscribe to and receive real-time quotes, DOM, and chart data
- Handle market data streams with proper error handling
- Manage subscriptions and unsubscribe properly
- Process tick chart data correctly
Required Tests
1. WebSocket Connection and Authorization
Purpose: Establish a secure WebSocket connection and authenticate for market data access.
Test Steps:
- Open WebSocket connection to market data endpoint
- Send authorization message with access token
- Verify successful authentication response
- Test connection stability and reconnection handling
- Verify proper error handling for invalid tokens
Example Implementation:
Validation Criteria:
- ✅ WebSocket connection establishes successfully
- ✅ Authorization message is accepted
- ✅ Connection remains stable during testing
- ✅ Invalid tokens are rejected appropriately
- ✅ Connection can be re-established after disconnection
2. Quote Subscription and Data Reception
Endpoint: md/subscribeQuote
Purpose: Subscribe to real-time quote data for specified contracts.
Test Steps:
- Subscribe to quote data for a valid contract symbol
- Verify subscription confirmation response
- Receive and validate quote data messages
- Test subscription with contract ID instead of symbol
- Unsubscribe and verify data stops flowing
Example Implementation:
Expected Quote Data:
Validation Criteria:
- ✅ Quote subscription succeeds with valid symbol/contract ID
- ✅ Real-time quote data is received continuously
- ✅ Quote data contains all expected fields
- ✅ Data timestamps are accurate and recent
- ✅ Unsubscription stops data flow immediately
- ✅ Invalid symbols are rejected appropriately
3. DOM (Depth of Market) Subscription
Endpoint: md/subscribeDOM
Purpose: Subscribe to real-time depth of market data showing bid/offer levels.
Test Steps:
- Subscribe to DOM data for a liquid contract
- Verify DOM data structure and content
- Test multiple price levels in bids and offers
- Verify real-time updates to DOM data
- Unsubscribe and verify data stops
Example Implementation:
Expected DOM Data:
Validation Criteria:
- ✅ DOM subscription succeeds with valid contract
- ✅ DOM data contains multiple bid/offer levels
- ✅ Price levels are properly ordered (bids descending, offers ascending)
- ✅ Real-time updates reflect market changes
- ✅ DOM data structure is consistent
- ✅ Unsubscription works correctly
4. Chart Data Subscription
Endpoint: md/getChart
Purpose: Request historical and real-time chart data for analysis.
Test Steps:
- Request chart data with specific parameters
- Verify historical data is returned
- Verify real-time chart updates are received
- Test different chart types (MinuteBar, DailyBar, Tick)
- Properly cancel chart subscription using returned ID
Example Implementation:
Expected Chart Response:
Expected Chart Data:
Validation Criteria:
- ✅ Chart request succeeds with valid parameters
- ✅ Historical data is returned with proper structure
- ✅ Real-time chart updates are received
- ✅ Subscription IDs are properly returned
- ✅ Chart cancellation works correctly
- ✅ Different chart types work as expected
5. Tick Chart Data Processing
Purpose: Request and process tick-level chart data for high-frequency analysis.
Test Steps:
- Request tick chart data with elementSize: 1
- Receive and process tick data packets
- Calculate actual tick prices and timestamps from relative values
- Handle multiple packets and end-of-history flag
- Verify tick data accuracy and completeness
Example Implementation:
Expected Tick Data:
Validation Criteria:
- ✅ Tick chart request succeeds
- ✅ Tick data packets are received and processed
- ✅ Relative prices and timestamps are calculated correctly
- ✅ End-of-history flag is properly handled
- ✅ Tick data accuracy is maintained
- ✅ Multiple packets are processed correctly
6. Histogram Subscription
Endpoint: md/subscribeHistogram
Purpose: Subscribe to real-time histogram data showing price distribution.
Test Steps:
- Subscribe to histogram data for a contract
- Verify histogram data structure
- Test histogram updates and refresh flags
- Verify price distribution data accuracy
- Unsubscribe and verify data stops
Example Implementation:
Expected Histogram Data:
Validation Criteria:
- ✅ Histogram subscription succeeds
- ✅ Histogram data contains price distribution
- ✅ Base price and items are properly structured
- ✅ Refresh flag indicates data updates
- ✅ Unsubscription works correctly
Best Practices
- Connection Management: Implement robust WebSocket connection handling with automatic reconnection
- Subscription Tracking: Keep track of all active subscriptions to properly unsubscribe
- Data Processing: Handle market data efficiently to avoid memory leaks
- Error Recovery: Implement proper error handling and recovery mechanisms
- Rate Limiting: Respect rate limits and implement backoff strategies
- Data Validation: Validate all incoming market data before processing
- Resource Cleanup: Always unsubscribe from data streams when no longer needed
Testing Checklist
- WebSocket connection establishes successfully
- Authorization with access token works correctly
- Quote subscription and data reception works
- DOM subscription provides proper depth data
- Chart data request returns historical and real-time data
- Tick chart data is processed correctly
- Histogram subscription provides data
- All subscription types can be unsubscribed properly
- Error handling works for invalid requests
- Connection stability is maintained during testing
- Resource cleanup is complete

