Skip to content

SSE Streaming

Deep dive into the Server-Sent Events streaming API.

Connection

The Events API uses standard SSE protocol over HTTP/2:

GET /api/stream
Accept: text/event-stream

Event Types

The stream emits different event types:

Event TypeDescription
filingSEC EDGAR filing notification
tradeForm 4 insider trade event
newsRSS news article
heartbeatKeep-alive ping (every 30s)

Filtering

Filter events by type using query parameters:

javascript
// Only receive Form 4 trades
const eventSource = new EventSource('/api/stream?types=trade');

// Multiple types
const eventSource = new EventSource('/api/stream?types=trade,filing');

Reconnection

The SSE protocol handles reconnection automatically. The server sends id fields that the browser uses for resumption:

javascript
eventSource.addEventListener('error', (event) => {
  if (eventSource.readyState === EventSource.CONNECTING) {
    console.log('Reconnecting...');
  }
});

Backpressure

If the client falls behind, the server may drop events. Monitor the Last-Event-ID header to detect gaps.

Example: React Hook

typescript
import { useEffect, useState } from 'react';

interface Event {
  eventType: string;
  issuer: string;
  filedAt: string;
}

export function useEventStream() {
  const [events, setEvents] = useState<Event[]>([]);

  useEffect(() => {
    const source = new EventSource('/api/stream');

    source.onmessage = (e) => {
      const event = JSON.parse(e.data);
      setEvents((prev) => [event, ...prev].slice(0, 100));
    };

    return () => source.close();
  }, []);

  return events;
}

Built for traders who value data provenance.