1. Connect to the Crypto WebSocket API
wss://ws.coinapi.io/v1/2. Subscribe to Live Bitcoin Trades
After connecting, send a hello message:
{
"type": "hello",
"apikey": "YOUR_API_KEY",
"heartbeat": true,
"subscribe_data_type": ["trade"],
"subscribe_filter_symbol_id": [
"BITSTAMP_SPOT_BTC_USD$"
]
}This example subscribes to real-time BTC/USD trades from Bitstamp.
The normalized symbol:
BITSTAMP_SPOT_BTC_USDidentifies:
- BITSTAMP — exchange
- SPOT — market type
- BTC — base asset
- USD — quote asset
The $ suffix requests an exact symbol match rather than a prefix match.
3. Receive Live Trade Events
Incoming trade messages follow a consistent structure:
{
"type": "trade",
"symbol_id": "BITSTAMP_SPOT_BTC_USD",
"sequence": 2323346,
"time_exchange": "2013-09-28T22:40:50.0000000Z",
"time_coinapi": "2017-03-18T22:42:21.3763342Z",
"uuid": "770C7A3B-7258-4441-8182-83740F3E2457",
"price": 770.000000000,
"size": 0.050000000,
"taker_side": "BUY"
}The event identifies the market and includes the exchange timestamp, CoinAPI timestamp, execution price, size, sequence, trade identifier, and taker side.
WebSocket subscriptions can also be filtered by exchange, symbol, asset, and supported data type.