WebSocket API
WebSocket API Real-time Data Subscription Service
Overview
ChainStream DEX WebSocket API provides real-time data subscription services, supporting the following data types:
- Candle Data
- Token Stats
- Trade Events
- Wallet Trade Event
- Wallet Balance
- Token Holders
Base URL
Quick Start
1. Establish Connection
First, create a WebSocket connection and authenticate:
2. Subscribe to Data
Choose the data type you want to subscribe to:
3. Handle Data
Data Subscriptions
Candles Data
Get real-time price movement data for tokens.
Subscription Format
Parameters
Blockchain name, e.g., sol
Token contract address, e.g., 6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN
Candle period, supports: 1m, 5m, 15m, 1h, 4h, 1d
Response Data Format
WebSocket API returns shortened field names to optimize transmission efficiency, while SDK returns full field names to improve code readability.
Token Stats
Get real-time market statistics for tokens.
Subscription Format
Parameters
Blockchain name, e.g., sol
Token contract address, e.g., 6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN
Response Data Format
WebSocket API returns shortened field names to optimize transmission efficiency, while SDK returns full field names to improve code readability.
Trade Events
Get real-time token trading events.
Subscription Format
Parameters
Blockchain name, e.g., sol
Token contract address, e.g., 6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN
Response Data Format
WebSocket API returns shortened field names to optimize transmission efficiency, while SDK returns full field names to improve code readability.
Wallet Trade Event
Get real-time wallet trading event.
Subscription Format
Parameters
Blockchain name, e.g., sol
Token contract address, e.g., GDekof7TtgeBKJtoVpkvzPin5mvhxSDyoUY2c1FK1T3i
Response Data Format
WebSocket API returns shortened field names to optimize transmission efficiency, while SDK returns full field names to improve code readability.
Wallet Balance
Get real-time wallet balance information.
Subscription Format
Parameters
Blockchain name, e.g., sol
Wallet address, e.g., HN7cABqLq46Es1jh92dQQisAq662SmxELLLsHHe4YWrH
Response Data Format
WebSocket API returns shortened field names to optimize transmission efficiency, while SDK returns full field names to improve code readability.
Token Holders Statistics
Get real-time token holder statistics.
Subscription Format
Parameters
Blockchain name, e.g., sol
Token contract address, e.g., 6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN
Response Data Format
WebSocket API returns shortened field names to optimize transmission efficiency, while SDK returns full field names to improve code readability.
Usage Examples
Reconnection Strategy
Recommended to use exponential backoff for reconnection:
Usage Limits
Limit | Value | Description |
---|---|---|
Maximum Subscriptions | 100/connection | Excess will be rejected |
Message Size | 100KB | Excess will be truncated |
Heartbeat Interval | 30 seconds | Regular heartbeat required |
Best Practices
-
Connection Management
- Maintain a single WebSocket connection
- Implement automatic reconnection
- Send regular heartbeats
-
Error Handling
- Implement complete error handling
- Log detailed error information
- Use exponential backoff for reconnection
-
Performance Optimization
- Control subscription quantity
- Implement message queue mechanism
- Clean up unused subscriptions
Complete Example
Was this page helpful?