Skip to main content
Subscribe to real-time updates using Server-Sent Events.

Connection

const eventSource = new EventSource('/api/sse/events');

eventSource.onopen = () => {
  console.log('Connected to SSE');
};

eventSource.onerror = (error) => {
  console.error('SSE error:', error);
};

Event Types

feed_update

New post in the feed:
eventSource.addEventListener('feed_update', (event) => {
  const post = JSON.parse(event.data);
  console.log('New post:', post);
});

market_update

Market price change:
eventSource.addEventListener('market_update', (event) => {
  const update = JSON.parse(event.data);
  console.log('Market:', update.marketId, 'Price:', update.yesPrice);
});

notification

User notification:
eventSource.addEventListener('notification', (event) => {
  const notification = JSON.parse(event.data);
  console.log('Notification:', notification);
});

SSE Stats

Check connection statistics:
GET /api/sse/stats
Response:
{
  "connectedClients": 42,
  "channels": ["feed", "markets", "notifications"]
}