🔗 WebSocket V1 API
Introduction
Real-time market data streaming via WebSocket.
WebSocket V1 API
Stream real-time market data using WebSocket connections.
Connection
wss://ws.coinapi.io/v1/Authentication
Send a hello message after connecting:
{
"type": "hello",
"apikey": "YOUR_API_KEY",
"heartbeat": false,
"subscribe_data_type": ["trade"],
"subscribe_filter_symbol_id": ["BITSTAMP_SPOT_BTC_USD"]
}Data Types
| Type | Description |
|---|---|
trade | Individual trades |
quote | Best bid/ask |
book5 | Top 5 order book levels |
book20 | Top 20 order book levels |
book50 | Top 50 order book levels |
ohlcv | OHLCV candlestick updates |
Example: Subscribing to Trades
const ws = new WebSocket('wss://ws.coinapi.io/v1/');
ws.onopen = () => {
ws.send(JSON.stringify({
type: 'hello',
apikey: 'YOUR_API_KEY',
subscribe_data_type: ['trade'],
subscribe_filter_symbol_id: ['BITSTAMP_SPOT_BTC_USD']
}));
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Trade:', data);
};[!WARNING] WebSocket connections are limited based on your subscription plan. Ensure you handle reconnection logic in your application.
Heartbeat
Enable heartbeat to detect connection issues:
{
"type": "hello",
"apikey": "YOUR_API_KEY",
"heartbeat": true
}The server will send periodic heartbeat messages. If you don't receive one within the expected interval, reconnect.