Live release feed
Sub-second macro releases for FX backtests
Point-in-time history
Official CPI, jobs, GDP, and central-bank events with point-in-time history.
USD 25/month 14-day free trial
Start Free Trial
如何使用所有FXMacroData API终点:一个完整的指南 image
Share headline card X LinkedIn Email
Download

Implementation

How-To Guides

如何使用所有FXMacroData API终点:一个完整的指南

关于FXMacroData API中的每个公开终端点的步骤步骤介绍,从公告系列和发布日历到COT定位,商品,外汇汇率,实时SSE流,以及GraphQL批量.

其他语言版本 English
Share article X LinkedIn Email

在本指南的结尾,您将有FXMacroData API中的每个公开终端点的工作示例,从公告系列和发布日历到COT定位,贵金属价格,外汇汇率以及GraphQL接口,以便您可以选择任何宏观数据工作流程的正确工具.

预先要求

  • 一个FXMacroData帐户 没有任何其他信息.
  • 专业API密钥用于非美元和付费终端访问 (大多数终端请求都是免费的)
  • curl 对于命令行示例,或者Python 3.9+ requests 图书馆
  • 基本熟悉REST API和JSON响应
快速参考表
终点家族 航线 创作者
广告 /api/v1/公告/{货币}/{指标} 美元免费 · 其他用户为Pro
发布日程 /api/v1/日历/{货币} 免费的
数据目录 /api/v1/数据_目录/{货币} 免费的
机器人位置 /api/v1/cot/{货币} 美元免费 · 其他用户为Pro
金属 /api/v1/大宗商品/{指标} 专业键总是需要
外汇汇率 /api/v1/forex/{base}/{quote} 免费的
市场会议 /api/v1/市场_会议 免费的
图片QL /api/v1/graphql 美元+目录免费 · 其他用户的Pro

步骤1 宣布:历史指标系列

发布终点是FXMacroData的核心.它返回了任何支持的宏观经济指标的标准化,时间时间序列.每个行都包含观察日期,发布值和官方出版物的确切的Unix时间,为您提供第二级的事件驱动研究和后台测试精度.

美元请求没有API密钥.对于任何其他货币,添加你的密钥作为查询参数. 使用 start_date 现在我 end_date (YYY-MM-DD) 缩小窗口;默认是过去365天.

# USD inflation series — no key needed
curl "https://fxmacrodata.com/api/v1/announcements/usd/inflation"

# AUD policy rate — Pro key required
curl "https://fxmacrodata.com/api/v1/announcements/aud/policy_rate?api_key=YOUR_API_KEY"

# EUR GDP with a custom date range
curl "https://fxmacrodata.com/api/v1/announcements/eur/gdp?start_date=2024-01-01&end_date=2026-03-01&api_key=YOUR_API_KEY"
{
  "currency": "USD",
  "indicator": "inflation",
  "has_official_forecast": false,
  "start_date": "2025-03-01",
  "end_date": "2026-03-30",
  "data": [
    {
      "date": "2026-02-01",
      "val": 2.8,
      "announcement_datetime": 1741082400,
      "pct_change": -0.5,
      "pct_change_12m": -6.7
    }
  ]
}

没有什么. announcement_datetime 字段是数据正式发布的确切时刻符 (秒,UTC). 用它来对应事件研究,避免后台测试的前性. 浏览可用指标子,以任何货币的数据目录 (步骤 3) 或在 API数据文件现在我们要做什么?


步骤2 发布日程:即将公布的时间

日历终点返回给定货币的每一个即将发布的宏发布的计划UTC公告时间. 使用它来计划在新数据发布时发射的有针对性的获取,而不是在固定间隔内持续进行投票.

没有API键. 过到特定的指标,可选 indicator 查询参数 特殊货币代码 COMM 返回商品发布时间表.

# All upcoming releases for USD
curl "https://fxmacrodata.com/api/v1/calendar/usd"

# Filter to a single indicator
curl "https://fxmacrodata.com/api/v1/calendar/usd?indicator=non_farm_payrolls"

# Commodity release schedule
curl "https://fxmacrodata.com/api/v1/calendar/COMM"
{
  "currency": "USD",
  "indicator": "non_farm_payrolls",
  "data": [
    {
      "release": "non_farm_payrolls",
      "announcement_datetime": 1746540600,
      "requires_api_key": false
    }
  ]
}

转换时间为可读UTC时间 datetime.fromtimestamp(ts, tz=timezone.utc) 在Python或 new Date(ts * 1000).toISOString() 在JavaScript中. 查看完整的调度模式, 如何使用发布日历API来安排指标检索现在我们要做什么?


步骤3 数据目录:发现可用的指标

在编写针对特定指标的代码之前,查询目录以确认货币的可用性. 响应将每个指标映射到其可读名字,单位,发布频率以及中央银行是否发布官方预测.

# List all indicators for EUR — no key required
curl "https://fxmacrodata.com/api/v1/data_catalogue/eur"

# Include routing and auth discovery metadata per indicator
curl "https://fxmacrodata.com/api/v1/data_catalogue/usd?include_capabilities=true"
{
  "gdp": {
    "name": "GDP Growth",
    "unit": "%QoQ",
    "frequency": "Quarterly",
    "has_official_forecast": false
  },
  "inflation": {
    "name": "Inflation (CPI)",
    "unit": "%YoY",
    "frequency": "Monthly",
    "has_official_forecast": false
  },
  "policy_rate": {
    "name": "Policy Rate",
    "unit": "%",
    "frequency": "Meeting",
    "has_official_forecast": true
  }
}

答案中的顶级密钥是正确的. {indicator} 支持货币包括美元,欧元,英,日元,澳元,CAD,瑞郎,新西兰元,CNY,Sgd,SEK,DKK,PLN和布拉里. 通过 include_coverage=true 通过一个单一的响应来获得跨货币可用性格.


第4步 COT定位:投机期货数据

交易者的承诺终点提供了CFTC对外汇期货合约的每周定位数据.它显示了非商业 (投机性),商业的 (对冲) 和非报告参与者之间的总开放利息分成.

支持货币:美元,欧元,英,日元,澳元,CAD,瑞郎,新西兰元.美元是免费的;所有其他货币都需要Pro键.

# USD COT history — free
curl "https://fxmacrodata.com/api/v1/cot/usd"

# EUR COT with a custom date range
curl "https://fxmacrodata.com/api/v1/cot/eur?start_date=2025-01-01&api_key=YOUR_API_KEY"
{
  "currency": "EUR",
  "instrument": "EURO FX - CHICAGO MERCANTILE EXCHANGE",
  "fx_overlay": { "pair": "EUR/USD" },
  "start_date": "2025-01-07",
  "end_date": "2026-03-25",
  "data": [
    {
      "date": "2026-03-18",
      "announcement_datetime": 1742493000,
      "open_interest": 812345,
      "noncommercial_long": 185000,
      "noncommercial_short": 92000,
      "noncommercial_net": 93000,
      "commercial_long": 203000,
      "commercial_short": 310000,
      "commercial_net": -107000,
      "nonreportable_long": 21000,
      "nonreportable_short": 9000
    }
  ]
}

没有什么. noncommercial_net 投机长减短是外汇交易者最常引用的定位指标. announcement_datetime for the Friday 3:30 PM ET CFTC publication. For EUR pair context see the 欧元政策利率文件现在我们要做什么?


Step 5 — Metals: gold, silver, and platinum prices

金属终点返回来自皇家造币厂 (LBMA固定) 的贵金属的每日价格序列.这些序列作为跨资产宏观输入有用,特别是用于跟踪安全避险流和美元相关动态.

专业API键对于此终端点是需要的.可用指标: gold没有人知道. silver没有人知道. platinum现在我们要做什么?

# Gold LBMA PM Fix daily prices
curl "https://fxmacrodata.com/api/v1/commodities/gold?api_key=YOUR_API_KEY"

# Silver with a date range
curl "https://fxmacrodata.com/api/v1/commodities/silver?start_date=2025-01-01&api_key=YOUR_API_KEY"

# Platinum spot
curl "https://fxmacrodata.com/api/v1/commodities/platinum?api_key=YOUR_API_KEY"
{
  "currency": "COMM",
  "indicator": "gold",
  "has_official_forecast": false,
  "start_date": "2025-03-30",
  "end_date": "2026-03-30",
  "data": [
    {
      "date": "2026-03-28",
      "val": 2870.00,
      "pct_change": 1.2,
      "pct_change_12m": 30.1
    }
  ]
}

答案的形状与公告终点相同,因此您可以重复使用相同的解析代码. 注意 announcement_datetime 现在是 null 仅用于官方每月发布的事件.


第6步 外汇汇汇率:每日现货价格系列

外汇终点为任何支持的货币对返回每日OHLC现货率数据.不需要API键.使用它将宏观指标发布与反向测试或图形可视化工作流程的同时汇率相一致.

通过基数和引号作为单独的路径段 (例如 /forex/eur/usd 增加与 技术指标重叠的 indicators 查询参数

# EUR/USD daily rates — no key required
curl "https://fxmacrodata.com/api/v1/forex/eur/usd"

# AUD/JPY with a custom date range
curl "https://fxmacrodata.com/api/v1/forex/aud/jpy?start_date=2025-01-01"

# GBP/USD with technical indicators overlaid
curl "https://fxmacrodata.com/api/v1/forex/gbp/usd?indicators=sma_20,rsi_14"
{
  "base": "EUR",
  "quote": "USD",
  "start_date": "2025-03-30",
  "end_date": "2026-03-30",
  "data": [
    {
      "date": "2026-03-28",
      "close": 1.0832,
      "open": 1.0821,
      "high": 1.0867,
      "low": 1.0798
    }
  ]
}

步骤7 市场会议:实时会议状态

市场会话终点返回所有四个主要外汇会话的当前开放/关闭状态悉尼,东京,伦敦和纽约,以及主动重叠窗口.不需要API键.使用它将时间敏感的自动化关闭到高流动性窗口或注释会话边界的图表.

# Real-time snapshot — no key required
curl "https://fxmacrodata.com/api/v1/market_sessions"

# Historical snapshot for scheduling or testing
curl "https://fxmacrodata.com/api/v1/market_sessions?at=2026-03-28T12:00:00Z"
{
  "now_utc": "2026-03-30T08:47:00Z",
  "now_unix": 1743324420,
  "is_market_day": true,
  "sessions": [
    {
      "name": "London",
      "is_open": true,
      "seconds_to_close": 25200,
      "currencies": ["EUR", "GBP", "CHF"],
      "open_utc": "2026-03-30T07:00:00Z",
      "close_utc": "2026-03-30T15:00:00Z"
    }
  ],
  "overlaps": [
    {
      "name": "London / New York",
      "is_active": false,
      "priority": "high",
      "start_utc": "2026-03-30T12:00:00Z",
      "end_utc": "2026-03-30T16:00:00Z",
      "notable_pairs": ["EUR/USD", "GBP/USD", "USD/CHF"],
      "duration_hours": 4
    }
  ]
}

伦敦/纽约重叠是交易日流动性最高的窗口,是宏观发布最频繁导致最大现货移动的时刻. is_market_day: false 周末和主要市场假期可以跳过自动化.


步骤8 GraphQL:在一个请求中批量多个查询

FXMacroData 暴露了一个 GraphQL 终点,它完全反映了 REST 表面的规则,相同的字段名称,相同数据,但允许您声明您所需要的字域,并将多个查询结合到单个HTTP回复. 并且 英政策利率 并且 时间表,即一个POST而不是三个GET.

发送一个 POST 现在 https://fxmacrodata.com/api/v1/graphql 包含一个 JSON 文体 query 您的API键作为URL查询参数.可用的根字段是 announcements没有人知道. dataCatalogue没有 calendar现在我们要做什么?

# Single free USD query — no key required
curl -s -X POST "https://fxmacrodata.com/api/v1/graphql" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "{ announcements(currency: \"USD\", indicator: \"inflation\") { currency indicator data { date val pctChange } } }"
  }'

# Batched: EUR inflation + GBP policy rate in one request
curl -s -X POST "https://fxmacrodata.com/api/v1/graphql?api_key=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "query { eurCPI: announcements(currency: \"EUR\", indicator: \"inflation\") { data { date val } } gbpRate: announcements(currency: \"GBP\", indicator: \"policy_rate\") { data { date val } } }"
  }'
{
  "data": {
    "eurCPI":  { "data": [{ "date": "2026-02-28", "val": 2.3 }] },
    "gbpRate": { "data": [{ "date": "2026-03-20", "val": 4.5 }] }
  }
}
建议: 使用查询别名 (如 eurCPI: 避免在分批量时出现域名冲突. announcements 每个别名成为一个单独的密钥 data 答案对象.

GraphQL 返回 HTTP 200 即使查询字段失败 错误出现在顶级字段中 errors 对于一个完整的 Python 和 JavaScript 实现,包括错误处理和批处理模式,请参阅 如何通过GraphQL查询FXMacroData现在我们要做什么?


步骤10 端到端Python工作流程

下面的片段将最常见的模式按顺序汇集在一起:发现可用指标,检查下一个计划发布,在单个 GraphQL 请求中获取两个指标系列,然后在路由输出之前条件检查市场会话状态.

import requests
from datetime import datetime, timezone

BASE = "https://fxmacrodata.com/api/v1"
API_KEY = "YOUR_API_KEY"


def params(require_key: bool = True) -> dict:
    return {"api_key": API_KEY} if require_key else {}


# 1. Discover available indicators for AUD (free)
catalogue = requests.get(f"{BASE}/data_catalogue/aud", params=params(False), timeout=10)
catalogue.raise_for_status()
print("AUD indicators:", list(catalogue.json().keys())[:5])

# 2. Check the next USD non-farm payrolls release timestamp (free)
cal = requests.get(f"{BASE}/calendar/usd", params={"indicator": "non_farm_payrolls"}, timeout=10)
cal.raise_for_status()
events = cal.json().get("data", [])
if events:
    ts = events[0]["announcement_datetime"]
    dt = datetime.fromtimestamp(ts, tz=timezone.utc)
    print(f"Next NFP release: {dt.strftime('%Y-%m-%d %H:%M UTC')}")

# 3. Fetch EUR inflation + AUD policy rate in one GraphQL request (Pro key)
gql_query = """
query {
  eurCPI: announcements(currency: "EUR", indicator: "inflation") {
    data { date val pctChange }
  }
  audRate: announcements(currency: "AUD", indicator: "policy_rate") {
    data { date val }
  }
}
"""
resp = requests.post(
    f"{BASE}/graphql",
    params={"api_key": API_KEY},
    json={"query": gql_query},
    timeout=15,
)
resp.raise_for_status()
payload = resp.json()
if "errors" in payload:
    raise RuntimeError(payload["errors"])
data = payload["data"]

eur_latest = data["eurCPI"]["data"][-1]
aud_latest = data["audRate"]["data"][-1]
print(f"EUR CPI  {eur_latest['date']}: {eur_latest['val']}%")
print(f"AUD Rate {aud_latest['date']}: {aud_latest['val']}%")

# 4. Check market sessions before triggering a trade alert (free)
sessions_resp = requests.get(f"{BASE}/market_sessions", timeout=10)
sessions_resp.raise_for_status()
session_data = sessions_resp.json()

if session_data["is_market_day"]:
    for overlap in session_data.get("overlaps", []):
        if overlap["is_active"] and overlap["priority"] == "high":
            print(f"High-liquidity window active: {overlap['name']}")
else:
    print("Market closed — skipping alert")

你所取得的成就

  • ✓从 图片中获取了具有精确发布时间的历史指标系列 广告 终点
  • ✓ 查询了来自 发布日程 终点
  • ✓ 发现了每种货币的可用指标 数据目录 终点
  • ✓从 投机期货定位中获取 其他 终点
  • ✓从 价格系列中提取贵金属 金属 终点
  • ✓ 调整了来自欧元区的宏观数据,并与现货汇率进行了对比 外汇汇率 终点
  • ✓ 检查了现场会议状态 市场会议 终点
  • ✓ 通过单个往返方式对多个指标查询进行批处理 图片QL 终点

您可以建立下一个

现在您在FXMacroData API中每个公开终端点都有工作示例.

  • 通过 GraphQL 批处理来替换顺序的 REST 调用. 任何地方,你做三个或更多独立的GET请求,一个单个GraphQL POST可以取代它们. 如何通过GraphQL查询FXMacroData现在我们要做什么?
  • 层COT定位在速度差距上. 将从COT终点的投机净值与政策利率系列结合起来,构建一个跨G8货币宇宙的复合宏观信号.
  • 调整金属价格与货币的发布. 将金属终点的黄金与澳元或美元的公告系列结合起来,以随着时间的推移跟踪安全避难所和美元的相关性.

汇率数据团队

Blogroll

AI Answer-Ready

Key Facts

Page
How To Use All FXmacrodata API Endpoints
Section
Articles
Canonical URL
https://fxmacrodata.com/zh/articles/how-to-use-all-fxmacrodata-api-endpoints
Source
FXMacroData editorial and official publisher references
Last Updated
2026-06-15 11:01 UTC

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 How To Use All FXmacrodata API Endpoints 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.