Documentation

Quickstart

Create an API key in your dashboard, open a WebSocket to the stream endpoint and handle release messages in your strategy.

import json, websocket  # pip install apimacro websocket-client

API_KEY = "am_live_xxxxxxxxxxxxxxxx"

def on_message(ws, raw):
    msg = json.loads(raw)
    if msg["type"] != "release":
        return
    ind, bias = msg["indicator"], msg["interpretation"]["currency_bias"]
    print(ind["name"], msg["actual"], "vs", msg["consensus"], "->", ind["currency"], bias)
    if ind["currency"] == "USD" and bias != "neutral" and msg["surprise"]["size"] != "small":
        side = "SELL" if bias == "bullish" else "BUY"   # gold usually moves against USD
        print("XAUUSD", side)

ws = websocket.WebSocketApp(
    "wss://stream.apimacro.com/v1/stream",
    header={"Authorization": f"Bearer {API_KEY}"},
    on_message=on_message,
)
ws.run_forever()

Authentication

Send your API key in the Authorization header, or as the api_key query parameter when your client cannot set headers. Keys start with am_live_ and are shown only once: if you lose one, regenerate it from the dashboard (the old key stops working immediately).

HTTP
Authorization: Bearer am_live_xxxxxxxxxxxxxxxx

# or
wss://stream.apimacro.com/v1/stream?api_key=am_live_xxxxxxxxxxxxxxxx

Plans & delivery

Every plan receives the same data. The plan sets how fast each release is pushed after ApiMacro has verified it, and how many bots can be connected at the same time.

PlanDelivery after verificationLive connectionsPrice
Starter+1 s1€20/month
Pro+250 ms3€45/month
UltraReal time5€80/month

Choosing your data

Choose countries, categories and a minimum impact in Dashboard → Data feed. The selection applies to all your keys. A bot can narrow it further for its own connection with a subscribe message; it can never widen it.

→ client
{"op":"subscribe","countries":["US"],"categories":["labor","inflation"],"min_impact":"high"}

WebSocket stream

The stream sends JSON messages. A heartbeat is sent every 15 seconds; if you miss two, reconnect. Every message carries a seq number: a gap means you missed a message, and the REST API can fill it.

← server
{"type":"heartbeat","seq":18229,"t":"2026-11-06T13:29:45.000Z"}

Message format

Every message has a type and a monotonically increasing seq. Four types exist:

  • ›armed — sent about 60 s before a scheduled release, with the consensus and previous value, so your bot is ready.
  • ›release — the official value as soon as it is verified, with the surprise and the interpretation.
  • ›correction — a fix to a value already sent (same event_id).
  • ›statement — central bank decisions: the rate, and the statement headline.
release
{
  "type": "release",
  "seq": 18231,
  "event_id": "US.NONFARM_PAYROLLS.2026-11-06",
  "indicator": {
    "id": "US.NONFARM_PAYROLLS",
    "name": "Nonfarm Payrolls",
    "country": "US",
    "currency": "USD",
    "category": "labor",
    "impact": "high",
    "source": "bls.gov"
  },
  "period": "2026-11",
  "unit": "K",
  "actual": 143,
  "consensus": 110,
  "previous": 22,
  "surprise": {
    "vs_consensus": 33,
    "vs_consensus_pct": 30,
    "direction": "above",
    "size": "large"
  },
  "interpretation": {
    "higher_is": "bullish",
    "currency_bias": "bullish",
    "market_bias": {
      "DXY": "up",
      "EURUSD": "down",
      "XAUUSD": "down",
      "US500": "down"
    }
  },
  "timestamps": {
    "scheduled": "2026-11-06T13:30:00.000Z",
    "detected": "2026-11-06T13:30:00.312Z",
    "sent": "2026-11-06T13:30:00.312Z"
  },
  "plan_delay_ms": 0
}
armed
{"type":"armed","seq":18230,"event_id":"US.NONFARM_PAYROLLS.2026-11-06","scheduled":"2026-11-06T13:30:00.000Z","consensus":110,"previous":22,"unit":"K"}
correction
{"type":"correction","seq":18240,"event_id":"US.NONFARM_PAYROLLS.2026-11-06","field":"actual","value":142,"replaces_seq":18231}
statement
{"type":"statement","seq":18301,"event_id":"US.FOMC.2026-11","headline":"FOMC lowers target range by 25bp to 4.00%-4.25%","source":"federalreserve.gov"}

Field reference

The fields a bot needs to decide. The trading fields (surprise, interpretation) can be switched off in Data feed. They are data, not investment advice: your strategy decides.

FieldMeaning
actual / consensus / previousPublished value, market expectation (null when not available) and previous value, in unit.
surprise.vs_consensusactual − consensus, in unit.
surprise.vs_consensus_pctThe same difference as a percentage of the consensus.
surprise.directionabove, below or inline.
surprise.sizesmall (< 5 %), medium (5–20 %) or large (≥ 20 %).
interpretation.higher_isWhat a higher value usually means for the currency: bullish or bearish (e.g. bearish for unemployment).
interpretation.currency_biasCombined reading of this release for the currency: bullish, bearish or neutral.
interpretation.market_biasUsual direction of the main related markets, e.g. {"EURUSD":"down","XAUUSD":"down"}.
timestamps.scheduled / detected / sentOfficial time, verification by ApiMacro, and delivery to you.
plan_delay_msDelay applied by your plan: 1000 (Starter), 250 (Pro), 0 (Ultra).

REST API

REST endpoints use the same API key and return JSON.

GET/v1/calendarUpcoming scheduled releases
GET/v1/releasesRecent releases (paginated)
GET/v1/events/{event_id}One event and its history
cURL
curl -H "Authorization: Bearer $APIMACRO_KEY" \
  "https://api.apimacro.com/v1/calendar?country=US&from=2026-11-01"

Regions

Connect to the region closest to your bot (usually your broker's data centre). The global hostname routes you automatically. At launch, two regions are open; the others follow.

Globalstream.apimacro.com
Ashburnus-east.stream.apimacro.comAt launch
Londoneu-west.stream.apimacro.comAt launch
Torontoca-central.stream.apimacro.comPlanned
São Paulosa-east.stream.apimacro.comPlanned
Frankfurteu-central.stream.apimacro.comPlanned
Johannesburgaf-south.stream.apimacro.comPlanned
Singaporeap-southeast.stream.apimacro.comPlanned
Tokyoap-northeast.stream.apimacro.comPlanned
Sydneyap-south.stream.apimacro.comPlanned

SDKs

Official SDKs handle reconnection, heartbeats and sequence gap detection.

install
pip install apimacro
npm install @apimacro/sdk

MT5 Expert Advisor

Download the Expert Advisor from your dashboard, add stream.apimacro.com to Tools → Options → Expert Advisors → Allow WebRequest, then attach it to any chart.

ApiMacro.mq5
// ApiMacro.mq5 — attach to any chart
input string ApiKey = "am_live_xxxxxxxxxxxxxxxx";

int OnInit() {
   if(!AM_Connect("wss://stream.apimacro.com/v1/stream", ApiKey))
      return INIT_FAILED;
   EventSetMillisecondTimer(10);
   return INIT_SUCCEEDED;
}

void OnTimer() {
   AMRelease r;
   while(AM_Poll(r)) {
      // r.currency_bias: "bullish" | "bearish" | "neutral", r.surprise_size: "small" | "medium" | "large"
      if(r.currency == "USD" && r.surprise_size != "small") {
         if(r.currency_bias == "bullish") Print(r.name, " beat -> USD up, XAUUSD down");
         if(r.currency_bias == "bearish") Print(r.name, " miss -> USD down, XAUUSD up");
      }
   }
}

Limits

Live WebSocket connections depend on your plan: 1 (Starter), 3 (Pro), 5 (Ultra), and one connection per API key. Up to 5 active keys per account. REST: 60 requests per minute per key. Going over a limit returns 429 (REST) or closes the newest connection (WebSocket).

Errors

Errors are returned as JSON with a code and a message.

401invalid_api_key
403subscription_inactive
403key_revoked
409connection_limit_reached
429rate_limited
500internal_error
{"error":{"code":"invalid_api_key","message":"The API key is invalid or revoked."}}