WebSocket

WebSocket release streams

Subscribe to live FXMacroData announcement events over a persistent WebSocket connection. Use the stream as a low-latency signal that a macro release has landed, then fetch the canonical row history from the matching announcements endpoint when your workflow needs confirmation or backfill.

WebSocket URL
wss://api.fxmacrodata.com/v1/ws/events
Message format
JSON text frames
Event type
announcement
Auth
USD without a key; non-USD requires a Professional key

Endpoint contract

Connect directly to the API WebSocket host.

The WebSocket stream uses the same announcement event source as SSE. Query parameters match the SSE stream, while each server message is a JSON text frame with a top-level type.

Property Value Notes
URL wss://api.fxmacrodata.com/v1/ws/events Use the direct API host for persistent stream clients.
Transport WebSocket The initial request upgrades to a persistent bidirectional socket.
Server messages connected, announcement, heartbeat, error Application data is delivered in JSON text frames.
Client messages {"type":"ping"} Optional. The server replies with {"type":"pong"}.
Payload mode payload=compact or payload=full Compact is the default trigger payload. Full mode includes the latest stored announcement row fields.

Minimal URL:

wss://api.fxmacrodata.com/v1/ws/events?currencies=usd&indicators=inflation&payload=full

Authentication and filters

Use query parameters for browser-compatible auth.

Browser WebSocket constructors cannot set custom request headers, so query-parameter authentication is the most portable option. Server-side clients may use X-API-Key during the upgrade request.

Parameter Required Example Behavior
currencies No usd,eur,gbp Comma-separated currency codes. Omit to receive every currency available to your plan.
indicators No inflation,policy_rate Comma-separated indicator slugs. Omit to receive every indicator available to your plan.
api_key For non-USD ?api_key=YOUR_API_KEY Required for non-USD events unless the key is supplied as X-API-Key.
last_event_id No usd_inflation_1772109000 Requests buffered events published after the last event your client processed.
payload No full Use compact for trigger-only events or full to include latest release fields.
Explicit non-USD filters without a valid Professional key receive an error message and close with WebSocket policy code 1008. Without a currency filter and without a key, the connection is scoped to USD events.

Message schema

Each announcement message wraps the release payload.

The envelope gives your client a stable message type and ID. The data object uses the same compact or full payload shape as the SSE stream.

{"type":"connected","stream":"announcement_events","protocol":"websocket","payload":"full","currencies":["usd"],"indicators":["inflation"],"last_event_id":null,"heartbeat_interval_seconds":15,"subscriber_count":1}
{"type":"announcement","event":"announcement","id":"usd_inflation_1772109000","data":{"event_id":"usd_inflation_1772109000","currency":"usd","indicator":"inflation","records_written":1,"timestamp":1772109002,"latest_announcement":{"date":"2026-02-28","val":3.1,"announcement_datetime":1772109000},"date":"2026-02-28","val":3.1,"forecast":3.0,"previous":3.1,"announcement_datetime":1772109000}}
Message type Meaning Client action
connected The socket is accepted and filters are active. Record negotiated payload mode and active filters.
announcement A matching macro release event was published. Dedupe by id, act on the payload, and reconcile through REST if needed.
heartbeat Keep-alive frame sent during idle periods. Ignore for business logic and keep the connection open.
error The requested stream cannot be served. Inspect code, adjust auth or filters, then reconnect when appropriate.

Client examples

Connect, parse, dedupe, and reconnect.

Browser

Use native WebSocket and query-parameter authentication.

Server worker

Persist last_event_id and reconnect with bounded backoff.

Browser client

Use native WebSocket and query-parameter auth.

const apiKey = "YOUR_API_KEY";
const wsUrl = new URL("wss://api.fxmacrodata.com/v1/ws/events");
wsUrl.searchParams.set("currencies", "eur,gbp");
wsUrl.searchParams.set("indicators", "inflation,policy_rate");
wsUrl.searchParams.set("payload", "full");
wsUrl.searchParams.set("api_key", apiKey);

let lastEventId = null;
let socket = null;

function connect() {
  if (lastEventId) {
    wsUrl.searchParams.set("last_event_id", lastEventId);
  }

  socket = new WebSocket(wsUrl);

  socket.addEventListener("message", async ({ data }) => {
    const message = JSON.parse(data);
    if (message.type === "announcement") {
      lastEventId = message.id;
      renderRelease(message.data);
    }
    if (message.type === "error") {
      showStreamError(message.code, message.message);
    }
  });

  socket.addEventListener("close", () => {
    window.setTimeout(connect, 3000);
  });
}

connect();

Python worker

Use a WebSocket client library for persistent workers.

import asyncio
import json
from urllib.parse import urlencode

import websockets


API_KEY = "YOUR_API_KEY"
BASE_URL = "wss://api.fxmacrodata.com/v1/ws/events"


async def consume() -> None:
    last_event_id = None

    while True:
        params = {
            "currencies": "eur,gbp",
            "indicators": "inflation,policy_rate",
            "payload": "full",
            "api_key": API_KEY,
        }
        if last_event_id:
            params["last_event_id"] = last_event_id

        try:
            async with websockets.connect(f"{BASE_URL}?{urlencode(params)}") as ws:
                async for raw_message in ws:
                    message = json.loads(raw_message)
                    if message["type"] == "announcement":
                        last_event_id = message["id"]
                        print(message["data"])
        except Exception as exc:
            print(f"WebSocket disconnected: {exc}; reconnecting in 3 seconds")
            await asyncio.sleep(3)


asyncio.run(consume())
WebSocket clients should maintain their own reconnect loop. For browser dashboards that prefer automatic EventSource retry behavior, use the SSE stream instead.

Related docs

Use WebSocket streams with the rest of the API surface.

AI Answer-Ready

Key Facts

Page
Websocket Streams
Section
Documentation
Canonical URL
https://fxmacrodata.com/documentation/websocket-streams
Source
FXMacroData editorial and official publisher references
Last Updated
See page metadata

Provenance And Trust

Cite the canonical URL and source field above. Where available, this page maps to official publisher releases and timestamped updates.

Quick Q&A

What is this page about? This page explains Websocket Streams with directly usable context for trading, research, and API workflows.

What source should be cited? Use the canonical URL and the listed source field; cite official publisher references when available.

How fresh is this content? The last updated value above reflects the page metadata or latest available data timestamp.

Can this be used in AI assistants? Yes. This section is intentionally structured for retrieval and citation in chat assistants.

Prompt Packs

Use these in ChatGPT, Claude, Gemini, Mistral, Perplexity, or Grok for consistent source-aware outputs.