Skip to main content
The orderbook channel streams real-time orderbook updates for prediction markets. Use this channel to build orderbook visualizations, depth charts, and market depth analysis tools.

Connection

See the WebSocket overview for connection setup and endpoint details.

Subscribe

Subscribe to All Orderbooks

{
  "type": "subscribe",
  "channel": "orderbook",
  "all": true
}

Subscribe to Specific Tickers

{
  "type": "subscribe",
  "channel": "orderbook",
  "tickers": ["BTCD-25DEC0313-T92749.99", "SPX-25DEC0313-T5000"]
}

Unsubscribe

Unsubscribe from All Orderbooks

{
  "type": "unsubscribe",
  "channel": "orderbook",
  "all": true
}

Unsubscribe from Specific Tickers

{
  "type": "unsubscribe",
  "channel": "orderbook",
  "tickers": ["BTCD-25DEC0313-T92749.99"]
}

Response Format

When subscribed to the orderbook channel, you’ll receive messages with the following structure:
{
  "channel": "orderbook",
  "type": "orderbook",
  "market_ticker": "BTCD-25DEC0313-T92749.99",
  "yes_bids": {
    "0.45": 1000,
    "0.44": 500,
    "0.43": 200
  },
  "no_bids": {
    "0.55": 1500,
    "0.56": 800,
    "0.57": 300
  }
}

Response Fields

FieldTypeDescription
channelstringAlways "orderbook"
typestringMessage type
market_tickerstringMarket identifier
yes_bidsobjectMap of price (string) to quantity (number) for YES outcome bids
no_bidsobjectMap of price (string) to quantity (number) for NO outcome bids
The yes_bids and no_bids fields are objects where keys are price strings and values are quantities. The order of entries in these objects represents the orderbook depth.

Code Examples

// Dev endpoint — no API key required, but rate-limited.
// For production, use your production WS URL and add:
//   { headers: { "x-api-key": "YOUR_API_KEY" } }
// as the second argument to new WebSocket().
const WS_URL = "wss://dev-prediction-markets-api.dflow.net/api/v1/ws";

const ws = new WebSocket(WS_URL);

ws.onopen = () => {
  console.log("Connected to WebSocket");

  // Subscribe to all orderbook updates
  ws.send(
    JSON.stringify({
      type: "subscribe",
      channel: "orderbook",
      all: true,
    })
  );
};

ws.onmessage = (event) => {
  const message = JSON.parse(event.data);

  if (message.channel === "orderbook") {
    console.log("Orderbook update:", {
      ticker: message.market_ticker,
      yesBids: message.yes_bids,
      noBids: message.no_bids,
    });
  }
};

ws.onerror = (error) => {
  console.error("WebSocket error:", error);
};

ws.onclose = () => {
  console.log("WebSocket connection closed");
};
import "dotenv/config";

const API_KEY = process.env.DFLOW_API_KEY;
const WS_URL = process.env.DFLOW_PREDICTION_MARKETS_WS_URL;

// Market tickers to subscribe to
const marketTickers = ["BTCD-25DEC0313-T92749.99", "SPX-25DEC0313-T5000"];

if (!WS_URL || !API_KEY) {
  throw new Error(
    "Missing websocket credentials. Set DFLOW_PREDICTION_MARKETS_WS_URL and DFLOW_API_KEY."
  );
}

const ws = new WebSocket(WS_URL, {
  headers: {
    "x-api-key": API_KEY,
  },
});

ws.onopen = () => {
  console.log("Connected to WebSocket");

  // Subscribe to specific tickers for orderbooks
  ws.send(
    JSON.stringify({
      type: "subscribe",
      channel: "orderbook",
      tickers: marketTickers,
    })
  );
};

ws.onmessage = (event) => {
  const message = JSON.parse(event.data);
  console.log(`Orderbook update for ${message.market_ticker}:`, message);
};
interface OrderbookUpdate {
  channel: "orderbook";
  type: string;
  market_ticker: string;
  yes_bids: Record<string, number>;
  no_bids: Record<string, number>;
}