WebSocket APIConnection

Heartbeat

Receive
/ws
Server

Every 15 seconds the server sends a heartbeat carrying the current time. The first one arrives about 15 seconds after the connection opens. Echo its data back before the next one. A missing, late or different value closes the connection with code 1000 at the next heartbeat. The server does not respond to the echo.

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
data*integer

The server time, to echo back.

Formatint64
heartbeat
{  "type": "M",  "topic": "heartbeat",  "data": 1736696400000}

Reply

Send

Sent back on the same channel.

application/json
  1. payload
method*string
data*integer

The data of the latest heartbeat, unchanged.

Formatint64
echo
{  "method": "heartbeat",  "data": 1736696400000}