Connection
WebSocket Endpoint
Authentication
Provide the Access Token in the URL when establishing a connection:- Using SDK (Recommended)
- Using Native WebSocket
- Command Line Testing
The SDK handles connection and authentication automatically. Just call the subscribe method:
The SDK automatically detects connection status and establishes connection when needed. No need to manually call
connect().Connection Response
Upon successful authentication, you’ll receive a response like:Subscription Types
ChainStream WebSocket supports multiple data subscription types:Subscription Format Examples
Unsubscribe
Message Format
Request Messages
Connect Message (Authentication):Response Messages
Subscription Confirmation:Heartbeat
WebSocket connections require periodic heartbeat messages to stay active. Based on theping field in the connect response (usually 25 seconds), send heartbeats within this interval:
Complete Example
Best Practices
Performance Optimization
Use Filters
Subscribe only to needed data to reduce bandwidth. Use CEL expressions to filter data.
Batch Processing
Batch process high-frequency data instead of processing one by one. Use message queues for buffering.
Local Caching
Cache static data like token information to reduce repeated processing.
Connection Reuse
A single connection can subscribe to multiple channels. Avoid creating multiple connections.
Error Handling
- Listen for error events — Handle connection and data errors promptly
- Implement retry mechanism — Use exponential backoff for reconnection
- Log recording — Record key events for troubleshooting
- Graceful degradation — Switch to polling when WebSocket is unavailable
Resource Management
Related Documentation
WebSocket API Reference
Complete subscription types and parameters
Price Alert Bot
Hands-on: Build a price monitoring bot

