Skip to content

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
Active trial or subscription API 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. Announcement frames arrive only when a release is ingested; heartbeat frames keep idle connections observable.

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 connection (URL plus upgrade header):

wss://api.fxmacrodata.com/v1/ws/events?currencies=usd&indicators=inflation&payload=full
X-API-Key: YOUR_API_KEY

Authentication and filters

Send your key in the X-API-Key header.

The WebSocket stream is designed for server-side clients. Send your key as an X-API-Key header on the upgrade request; WebSocket libraries such as Node.js ws and Python websockets support custom headers. Live WebSocket delivery requires an active trial or subscription API key.

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.
X-API-Key header Yes X-API-Key: YOUR_API_KEY Your trial or subscription API key, sent on the upgrade request.
api_key No ?api_key=YOUR_API_KEY Legacy. Prefer the X-API-Key header; keys in URLs end up in logs.
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.
Missing, revoked, or ineligible keys receive an error message and close with WebSocket policy code 1008. Trial keys and active subscription keys can use the same live-delivery stream.

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.

Node.js

Use the ws package and send X-API-Key in the connection headers.

Server worker

Persist last_event_id and reconnect with bounded backoff.

Node.js worker

Send the key in the upgrade request headers.

import WebSocket from "ws";

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");

let lastEventId = null;

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

  const socket = new WebSocket(wsUrl, {
    headers: { "X-API-Key": process.env.FXMD_API_KEY },
  });

  socket.on("message", (raw) => {
    const message = JSON.parse(raw.toString());
    if (message.type === "announcement") {
      lastEventId = message.id;
      handleRelease(message.data);
    }
    if (message.type === "error") {
      process.stderr.write(`${message.code}: ${message.message}\n`);
    }
  });

  socket.on("close", () => {
    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",
        }
        if last_event_id:
            params["last_event_id"] = last_event_id

        try:
            async with websockets.connect(
                f"{BASE_URL}?{urlencode(params)}",
                additional_headers={"X-API-Key": API_KEY},
            ) 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. Older websockets releases name the header argument extra_headers. For a plain HTTP stream with built-in replay, 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.