WebSocket APIConnection

Reconnect notice

Receive
/ws
Server

Sent before a server shuts down, for example during a rollout. The connection keeps delivering for about graceMs, then closes with code 1001 and reason server draining.

On receiving it:

  1. Open a new connection and subscribe to every topic again.
  2. Keep reading the old connection until it closes. Both deliver during the overlap, so handle duplicates.
  3. If the new connection is refused, retry right away. The next attempt reaches a server that is not shutting down.

Treat the 1001 close as a reason to reconnect too, in case the notice was missed. graceMs is approximate, so do not schedule against it. event and reason may gain values, and an unknown one also means reconnect soon.

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

Reserved. It cannot be subscribed to, and its messages arrive unasked.

data*
shutdown
{  "type": "M",  "topic": "system",  "data": {    "event": "reconnect",    "reason": "server_shutdown",    "graceMs": 7431  }}