Server-Sent Events for real-time updates
const eventSource = new EventSource('/api/sse/events'); eventSource.onopen = () => { console.log('Connected to SSE'); }; eventSource.onerror = (error) => { console.error('SSE error:', error); };
eventSource.addEventListener('feed_update', (event) => { const post = JSON.parse(event.data); console.log('New post:', post); });
eventSource.addEventListener('market_update', (event) => { const update = JSON.parse(event.data); console.log('Market:', update.marketId, 'Price:', update.yesPrice); });
eventSource.addEventListener('notification', (event) => { const notification = JSON.parse(event.data); console.log('Notification:', notification); });
GET /api/sse/stats
{ "connectedClients": 42, "channels": ["feed", "markets", "notifications"] }