WebSocket APIRequests
Subscribe
Subscribes to the topic in params[0]. The server answers with a response carrying the
same requestId. For topics that keep a latest value, that value follows right after the
response as a normal message, then live updates. Treat it as best effort: it is absent
when nothing has been cached yet.
Subscribing again to a topic the connection already holds re-acknowledges it. Subscriptions do not carry over to a new connection, so subscribe again after reconnecting.
x-api-key<api-key>The API key in the handshake's x-api-key header. Use this where you can.
const payload = { "method": "subscribe", "requestId": 1, "params": [ "predictOrderbook/123" ]};const socket = new WebSocket("wss://ws.predict.fun/ws?apiKey=YOUR_API_KEY");socket.addEventListener("open", () => { socket.send(JSON.stringify(payload));});- payload
method*stringrequestId*RequestIdA number you choose, echoed on the response so you can match the two. Use a
non-negative one: the server answers a frame it cannot read with -1.
int64params*array<>The topic to subscribe to. Only the first entry is read.
1 <= items{ "method": "subscribe", "requestId": 1, "params": [ "predictOrderbook/123" ]}Reply
Sent back on the same channel.
- payload
The answer to a subscribe, unsubscribe or setLanguage request. A frame the server cannot
read (invalid JSON, an unknown method, or a missing requestId or params) is
answered with requestId -1 and the error invalid_json. A frame over 8 KiB closes
the connection.
type*stringrequestId*RequestIdA number you choose, echoed on the response so you can match the two. Use a
non-negative one: the server answers a frame it cannot read with -1.
int64success*booleanerror?Present only when success is false.
{ "type": "R", "requestId": 1, "success": true}