Skip to main content

Connection

Connect to the PredictIt WebSocket endpoint:
wss://api.delphiterminal.co/ws/prdi?api_key=YOUR_API_KEY
PropertyValue
ProtocolWebSocket (wss://)
Authenticationapi_key query parameter
KeepalivePing every 54 seconds
Timeout60 seconds without pong
Max Message Size16 KB

Subscribing to markets

Once connected, send a JSON message to subscribe using market_id:
{
  "action": "subscribe",
  "market_ids": ["34256"],
  "message_types": ["prices"]
}
FieldTypeRequiredDescription
actionstringYessubscribe or unsubscribe
market_idsarrayYesArray of PredictIt market identifiers (numeric strings)
message_typesarrayNo["prices"] only. Defaults to prices if omitted. No orderbook or trades available.

Unsubscribing

{
  "action": "unsubscribe",
  "market_ids": ["34256"]
}

Message types

Price messages

{
  "type": "prices",
  "data": {
    "venue": "PRDI",
    "market_id": "34256",
    "server_time": 1774762511552,
    "ingest_time": 1774762511553,
    "payload": {
      "type": "Ticker",
      "Ticker": {
        "price": 0.42,
        "yes_bid": 0.41,
        "yes_ask": 0.43,
        "volume": 0,
        "open_interest": 0
      }
    }
  }
}

Full example

const ws = new WebSocket("wss://api.delphiterminal.co/ws/prdi?api_key=YOUR_API_KEY");

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

  ws.send(JSON.stringify({
    action: "subscribe",
    market_ids: ["34256"],
    message_types: ["prices"]
  }));
};

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

  if (data.type === "prices") {
    console.log("Price update:", data.data);
  }
};

ws.onclose = () => console.log("Disconnected");
ws.onerror = (error) => console.error("WebSocket error:", error);

Important notes

  • Authentication required via api_key query parameter
  • Prices only — PredictIt does not provide orderbook depth or individual trade history
  • PredictIt data is sourced via REST polling (60-second intervals)
  • Only emits updates when market state changes (last trade price, best bid/ask)
  • Use market_id (PredictIt market identifier) to subscribe