🔗 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

TypeDescription
tradeIndividual trades
quoteBest bid/ask
book5Top 5 order book levels
book20Top 20 order book levels
book50Top 50 order book levels
ohlcvOHLCV 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.

Service StatusGitHub SDK