WebSocket API
Real-time subscriptions for prices, trades, and orderbook updates
WebSocket API
The WebSocket API provides real-time subscriptions for market data including prices, trades, and orderbook updates.
Access
Connection
connect
Establish a WebSocket connection.
disconnect
Close the WebSocket connection.
isConnected
Check connection status.
Subscriptions
Price Updates
Subscribe to real-time price updates.
PriceUpdate object:
Trade Updates
Subscribe to real-time trades.
TradeUpdate object:
Orderbook Updates
Subscribe to real-time orderbook changes.
OrderbookUpdate object:
Unsubscribe
Stop receiving updates for a channel.
Event Handlers
onError
Handle WebSocket errors.
onClose
Handle connection close events.
Configuration
Configure WebSocket behavior at client initialization:
Complete Example
The WebSocket automatically reconnects on disconnection. You can disable this by setting reconnect: false in options.
Best Practices
- Single Connection: Use one WebSocket connection per client instance
- Unsubscribe When Done: Clean up subscriptions to reduce bandwidth
- Handle Reconnection: Your callbacks persist through reconnections
- Error Handling: Always set up error handlers for production