WebSocket APITopics

Top of book

Receive
/ws
Server

Subscribe with predictTopOfBook/{marketId}. Each message holds the best bid, the best ask and the last settled order, taken from the market's order book. A message is sent only when one of them changes, including the quantity at the best price. The latest value is sent on subscribe.

Authorization

headerx-api-key<api-key>

The API key in the handshake's x-api-key header. Use this where you can.

Code Sample
const socket = new WebSocket("wss://ws.predict.fun/ws?apiKey=YOUR_API_KEY");socket.addEventListener("message", (event) => {  console.log(event.data);});

Messages

application/json
  1. payload
type*string
topic*string

The topic string the subscription was made with.

data*

The first level on each side of the market's order book. It has no timestamp, because a message is only sent on a change. To know how fresh the book is, read the order book.

quote
{  "type": "M",  "topic": "predictTopOfBook/123",  "data": {    "marketId": 123,    "bestBid": [      0.61,      2000    ],    "bestAsk": [      0.62,      1500    ],    "lastOrderSettled": {      "id": "987654321",      "price": "0.62",      "kind": "LIMIT",      "marketId": 123,      "side": "Ask",      "outcome": "Yes"    }  }}