Skip to main content

Connection

Connect to the WebSocket endpoint with your API key as a query parameter:
wss://api.tradingnews.press/v1/stream?api_key=YOUR_KEY
WebSocket streaming is available on the Pro plan only ($50/mo). Starter plan users will receive a connection rejection.

Firehose

The WebSocket is a firehose — once connected, all articles are pushed to you automatically as they arrive. There is no subscription step and no filtering. You receive everything.

Connection Limit

Each user is limited to 1 concurrent WebSocket connection. If you attempt to open a second connection, it will be rejected with close code 1008. Close your existing connection before opening a new one.

Message Format

Each message is a JSON object matching the article schema:
{
  "id": "01KNKV33C9DDADR1HRRWGCSA8V",
  "content": "BREAKING: Fed announces emergency rate cut",
  "urgency": "breaking",
  "sentiment": null,
  "published_at": "2026-04-07T14:30:00+00:00",
  "received_at": "2026-04-07T14:30:02.123456+00:00"
}

Reconnection

The server may close connections periodically. Implement automatic reconnection with exponential backoff:
import asyncio
import json
import websockets

async def stream_with_reconnect():
    backoff = 1
    while True:
        try:
            async with websockets.connect(
                "wss://api.tradingnews.press/v1/stream?api_key=YOUR_KEY"
            ) as ws:
                backoff = 1  # reset on success
                async for msg in ws:
                    article = json.loads(msg)
                    process(article)
        except websockets.ConnectionClosed:
            await asyncio.sleep(backoff)
            backoff = min(backoff * 2, 60)

Disconnection

The connection closes when:
  • Your plan is not Pro (close code 1008)
  • You already have an active connection (close code 1008)
  • Invalid API key (close code 1008)
  • Server maintenance (implement auto-reconnect)