Events (SSE)

Server-Sent Events (SSE) provide real-time streaming updates for admin dashboards. For programmatic market data streaming, use the WebSocket endpoint instead.

Overview

SSE is a one-way streaming protocol where the server pushes events to the client over a long-lived HTTP connection. The 4rho admin dashboard uses SSE for real-time activity feeds, audit logs, and system alerts.

SSE endpoints are admin-only and are not accessible via API keys. They require an authenticated admin session.

Connection

GET /admin/sse

Auth: Admin session cookie (not API-key accessible)

Connect using the browser EventSource API:

const source = new EventSource('/admin/sse', {
  withCredentials: true,
});

source.addEventListener('activity', (event) => {
  const data = JSON.parse(event.data);
  console.log('Activity:', data);
});

source.addEventListener('audit', (event) => {
  const data = JSON.parse(event.data);
  console.log('Audit log:', data);
});

source.addEventListener('alert', (event) => {
  const data = JSON.parse(event.data);
  console.log('System alert:', data);
});

source.onerror = () => {
  console.error('SSE connection lost, reconnecting...');
};

Event Types

Activity

Real-time platform activity such as trades, order placements, and user sign-ups.

{
  "type": "trade",
  "user_id": "...",
  "market_id": "...",
  "details": "Bought 1000 YES @ 0.52",
  "timestamp": 1709136000000
}

Audit

Admin action audit log entries (API key creation, market status changes, user management).

{
  "type": "market_pause",
  "admin_id": "...",
  "target": "market-id-1",
  "details": "Market paused by admin",
  "timestamp": 1709136000000
}

Alert

System-level alerts (high error rates, resource thresholds, service degradation).

{
  "type": "error_rate",
  "severity": "warning",
  "message": "Order error rate above 5% threshold",
  "timestamp": 1709136000000
}