WebSocket Streaming
Real-time orderbook data via WebSocket. Lower latency and bandwidth than REST polling. API key required.
Connection
Connect to the /ws/orderbook endpoint to receive live orderbook snapshots. Authentication is required — pass your API key as a query parameter.
wss://api.resolvedmarkets.com/ws/orderbook?apiKey=YOUR_API_KEYPass your API key via the apiKey query parameter. The server validates the key during the WebSocket handshake — invalid or missing keys receive a 401/403 HTTP response and the connection is rejected.
Message Flow
Connect
Open a WebSocket connection. The server immediately sends the list of available markets.
Receive markets list
Server sends { "type": "markets", "data": [...] } with all active markets.
Subscribe to a crypto
Send { "type": "subscribe", "crypto": "BTC" } to start receiving orderbook data for that crypto.
Receive orderbook updates
Server pushes { "type": "orderbook", "markets": [...] } every 2 seconds with live depth data.
Example: JavaScript
const API_KEY = "rm_your_key_here";
const ws = new WebSocket("wss://api.resolvedmarkets.com/ws/orderbook?apiKey=" + API_KEY);
ws.onopen = () => {
console.log("Connected");
// Subscribe to BTC orderbooks
ws.send(JSON.stringify({ type: "subscribe", crypto: "BTC" }));
};
ws.onmessage = (event) => {
const msg = JSON.parse(event.data);
if (msg.type === "markets") {
console.log("Available markets:", msg.data);
}
if (msg.type === "orderbook") {
for (const market of msg.markets) {
console.log(market.crypto, market.timeframe);
console.log(" UP best bid:", market.up?.bestBid);
console.log(" DOWN best ask:", market.down?.bestAsk);
}
}
};
ws.onclose = () => {
console.log("Disconnected — reconnect after 3s");
setTimeout(() => { /* reconnect logic */ }, 3000);
};Example: Python
import asyncio, json, websockets
async def stream():
API_KEY = "rm_your_key_here"
async with websockets.connect(f"wss://api.resolvedmarkets.com/ws/orderbook?apiKey={API_KEY}") as ws:
# Subscribe to ETH
await ws.send(json.dumps({"type": "subscribe", "crypto": "ETH"}))
async for message in ws:
data = json.loads(message)
if data["type"] == "orderbook":
for m in data["markets"]:
print(f"{m['crypto']} {m['timeframe']}: "
f"UP bid={m['up']['bestBid']}")
asyncio.run(stream())Server Messages
| Type | Frequency | Description |
|---|---|---|
markets | On connect + every 10s | Full list of active markets with crypto, timeframe, and IDs |
orderbook | Every 2 seconds | Live orderbook for subscribed crypto — UP/DOWN books with bids, asks, depth |
| ping | Every 30 seconds | Heartbeat — respond with pong (handled automatically by browsers) |
Client Messages
| Type | Payload | Description |
|---|---|---|
subscribe | { "type": "subscribe", "crypto": "BTC" } | Switch subscription to a different crypto (BTC, ETH, SOL, XRP) |
Important Notes
Pass your key as ?apiKey=hf_xxx in the connection URL. Connections without a valid key are rejected with 401/403.
The server evicts clients that don't respond to pings within 30 seconds. Implement reconnection logic in your client.
Sending a new subscribe message replaces the previous subscription. To monitor multiple cryptos, open multiple connections.