WebSocket

Real-time notifications and live updates via WebSocket.

Connection

Pass the JWT through the WebSocket subprotocol header so it does not appear in URLs or access logs:

const ws = new WebSocket(
  'wss://api.judgemarket.com/ws',
  ['judgemarket', `bearer.${token}`]
);

The legacy ?token= query form remains temporarily available for older clients, but new integrations should not use it.

The connection stays alive as long as the token is valid. When the access token expires, the connection will close and you should reconnect with a refreshed token.

Message Format

All messages are JSON with a type field:

{
  "type": "NOTIFICATION",
  "payload": {
    "title": "Order Filled",
    "content": "Your Bid order for Elon Musk was fully filled at 86.31 Φ."
  }
}

Message Types

  • NOTIFICATION — push notification (order filled, transfer received, reward claimed)

Reconnection

If the connection drops unexpectedly, implement exponential backoff:

let delay = 1000;
const maxDelay = 30000;

function reconnect(token) {
  setTimeout(() => {
    const ws = new WebSocket(
      'wss://api.judgemarket.com/ws',
      ['judgemarket', `bearer.${token}`]
    );
    ws.onclose = () => {
      delay = Math.min(delay * 2, maxDelay);
      reconnect(token);
    };
    ws.onopen = () => { delay = 1000; };
  }, delay);
}