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.

WebSocket URL
wss://api.resolvedmarkets.com/ws/orderbook?apiKey=YOUR_API_KEY
Authentication

Pass 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

1

Connect

Open a WebSocket connection. The server immediately sends the list of available markets.

2

Receive markets list

Server sends { "type": "markets", "data": [...] } with all active markets.

3

Subscribe to a crypto

Send { "type": "subscribe", "crypto": "BTC" } to start receiving orderbook data for that crypto.

4

Receive orderbook updates

Server pushes { "type": "orderbook", "markets": [...] } every 2 seconds with live depth data.

Example: JavaScript

Browser / Node.js
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

Python (websockets)
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

TypeFrequencyDescription
marketsOn connect + every 10sFull list of active markets with crypto, timeframe, and IDs
orderbookEvery 2 secondsLive orderbook for subscribed crypto — UP/DOWN books with bids, asks, depth
pingEvery 30 secondsHeartbeat — respond with pong (handled automatically by browsers)

Client Messages

TypePayloadDescription
subscribe{ "type": "subscribe", "crypto": "BTC" }Switch subscription to a different crypto (BTC, ETH, SOL, XRP)

Important Notes

API key required

Pass your key as ?apiKey=hf_xxx in the connection URL. Connections without a valid key are rejected with 401/403.

Auto-reconnect recommended

The server evicts clients that don't respond to pings within 30 seconds. Implement reconnection logic in your client.

One subscription at a time

Sending a new subscribe message replaces the previous subscription. To monitor multiple cryptos, open multiple connections.

WebSocket Streaming — API Docs | Resolved Markets