WebSocket API
Real-time crypto derivatives data streaming
Connection
Two protocols are supported. Choose based on your needs:
wss://apiv2.laevitas.ch/ws
Native WebSocket (W3C)
?apiKey=your-key
Industry standard - same protocol used by Deribit, Binance, OKX, Bybit, Hyperliquid
wss://apiv2.laevitas.ch/stream
Socket.IO v4
auth: { apiKey: 'your-key' }
Auto-reconnect, acknowledgements - requires Socket.IO client library
Channels
Real-time trade events with OI changes and strategy detection.
| {market} | futures |
| {exchange} | binance, deribit, okx, bybit, hyperliquid |
| {instrument} | Instrument name |
Quote-based OHLC with mark/index prices and liquidity.
| {market} | futures |
| {tf} | 1m, 5m, 15m, 30m, 1h, 4h, 12h, 1d |
Trade-based OHLC with volume breakdown and VWAP.
| {market} | futures |
| {tf} | 1m, 5m, 15m, 30m, 1h, 4h, 12h, 1d |
Payload Examples
Futures Trade Event
{
"trade_id": "401318266",
"instrument_name": "BTC-27MAR26",
"exchange": "deribit",
"direction": "sell",
"price": 93230,
"amount": 9000,
"contracts": 900,
"mark_price": 93220.37,
"index_price": 91523.43,
"open_interest": 328996550,
"oi_change": 1390
}
Options Trade Event
{
"trade_id": "401321563",
"instrument_name": "BTC-30JAN26-100000-C",
"strike": 100000,
"option_type": "C",
"direction": "sell",
"price": 0.0426,
"premium_usd": 48894.91,
"iv": 43.98,
"delta": -4.437,
"strategy": "BULL_DIAGONAL_SPREAD"
}
OHLC Ticker Event
{
"state": "live",
"instrument_name": "BTC-27MAR26",
"timeframe": "5m",
"mark_price_open": 93322.9,
"mark_price_high": 93326.78,
"mark_price_low": 93284.12,
"mark_price_close": 93294.52,
"oi_close": 3525.95
}
OHLC VT Event
{
"state": "live",
"instrument_name": "BTC-27MAR26",
"timeframe": "5m",
"open": 93302.5,
"high": 93317.5,
"low": 93302.5,
"close": 93317.5,
"vwap": 93306.59,
"buy_volume": 2030,
"sell_volume": 760
}
Operations
Subscribe
{
"id": 1,
"method": "subscribe",
"params": {
"channels": ["trades.futures.binance.BTCUSDT"]
}
}
Response
{
"id": 1,
"result": {
"subscriptionIds": ["sub_123"],
"channels": ["trades.futures.binance.BTCUSDT"]
}
}
Data Event
{
"channel": "trades.futures.binance.BTCUSDT",
"data": { "price": 93230, "direction": "buy", ... }
}
Unsubscribe
{
"id": 2,
"method": "unsubscribe",
"params": { "subscriptionId": "sub_123" }
}
Subscribe
socket.emit('subscribe', {
channel: 'trades.futures.binance.BTCUSDT'
}, (response) => {
console.log('ID:', response.subscriptionId);
});
Unsubscribe
socket.emit('unsubscribe', {
subscriptionId: 'sub-123'
});
Connection
Subscribe
Active Subscriptions
No active subscriptions
Events
Connect and subscribe to see events
Native WebSocket Examples
JavaScript / Node.js
const WebSocket = require('ws');
const ws = new WebSocket('wss://apiv2.laevitas.ch/ws?apiKey=your-api-key');
ws.on('open', () => {
console.log('Connected to WebSocket');
// Subscribe to BTC futures trades
ws.send(JSON.stringify({
id: 1,
method: 'subscribe',
params: { channels: ['trades.futures.binance.BTCUSDT'] }
}));
});
ws.on('message', (data) => {
const msg = JSON.parse(data);
// Handle subscription response
if (msg.id === 1 && msg.result) {
console.log('Subscribed:', msg.result.subscriptionIds);
}
// Handle data events
if (msg.channel && msg.data) {
const trade = msg.data;
console.log(`Trade: ${trade.direction} ${trade.amount} @ $${trade.price}`);
}
});
ws.on('close', () => console.log('Disconnected'));
Python
import websockets
import asyncio
import json
async def main():
uri = 'wss://apiv2.laevitas.ch/ws?apiKey=your-api-key'
async with websockets.connect(uri) as ws:
print('Connected to WebSocket')
# Subscribe to BTC futures trades
await ws.send(json.dumps({
'id': 1,
'method': 'subscribe',
'params': {'channels': ['trades.futures.binance.BTCUSDT']}
}))
async for message in ws:
msg = json.loads(message)
# Handle subscription response
if msg.get('id') == 1 and msg.get('result'):
print(f"Subscribed: {msg['result']['subscriptionIds']}")
# Handle data events
if 'channel' in msg and 'data' in msg:
trade = msg['data']
print(f"Trade: {trade['direction']} {trade['amount']} @ ${trade['price']}")
asyncio.run(main())
Socket.IO Examples
JavaScript / Node.js
const io = require('socket.io-client');
const socket = io('wss://apiv2.laevitas.ch/stream', {
transports: ['websocket'],
auth: { apiKey: 'your-api-key' }
});
socket.on('connect', () => {
console.log('Connected to WebSocket');
// Subscribe to BTC futures trades
const channel = 'trades.futures.binance.BTCUSDT';
socket.emit('subscribe', { channel }, (response) => {
console.log('Subscribed:', response.subscriptionId);
});
socket.on(channel, (data) => {
console.log(`Trade: ${data.direction} ${data.amount} @ $${data.price}`);
});
});
socket.on('disconnect', () => console.log('Disconnected'));
Python
import socketio
sio = socketio.Client()
@sio.event
def connect():
print('Connected to WebSocket')
# Subscribe to BTC futures trades
channel = 'trades.futures.binance.BTCUSDT'
sio.emit('subscribe', {'channel': channel},
callback=lambda r: print(f"Subscribed: {r['subscriptionId']}"))
@sio.on('trades.futures.binance.BTCUSDT')
def on_trade(data):
print(f"Trade: {data['direction']} {data['amount']} @ ${data['price']}")
@sio.event
def disconnect():
print('Disconnected')
sio.connect('wss://apiv2.laevitas.ch/stream',
auth={'apiKey': 'your-api-key'},
transports=['websocket'])
sio.wait()