在本指南结束时,您将能够正确认证,选择每个任务的正确终端点家族,并在FXMacroData API上进行生产准备的请求,而不必猜测路线结构或指标覆盖范围.
预先要求
- 对于非美元请求的FXMacroData帐户和API密钥
- 一个终端
curl或是像Python/Node.js这样的运行时间 - 基本熟悉JSON响应和URL查询参数
- 访问现场文件 文件
步骤1 - 开始与生产基地URL
所有公开示例都应该从生产API基础开始:
https://fxmacrodata.com/api/v1
你最常使用的终点家族是:
/announcements/{currency}/{indicator}对于历史上发布的值,announcement_datetime/calendar/{currency}对于即将发布的时间/catalogue/{currency}支持指标的可发现性/cot/{currency}交易者承诺定位/commodities/{indicator}对于大宗商品和能源系列/forex/{pair}现在我/market-sessions对于市场环境
步骤2 - 通过查询参数正确身份验证
在公共使用示例中,FXMacroData使用查询参数认证:
?api_key=YOUR_API_KEY
美元终端点访问可无关键,而非美元路线需要有效的关键.
# USD endpoint (no key required)
curl "https://fxmacrodata.com/api/v1/announcements/usd/inflation"
# Non-USD endpoint (key required)
curl "https://fxmacrodata.com/api/v1/announcements/aud/policy_rate?api_key=YOUR_API_KEY"
步骤3 - 在编码之前,了解可用的内容
当你不确定货币的指标时,首先调用目录路线. 这避免了硬编码假设.
curl "https://fxmacrodata.com/api/v1/catalogue/eur?api_key=YOUR_API_KEY"
然后使用指标页面索引 文档指标指数 确认路线路径和预期的场地.
步骤4 - 从公告终点中获取发布的数据
声明终点返回一个顶级对象加上 a data 历史版本的数组. 每一行包含一个时期结束 date没有 val并且一个 announcement_datetime 时间.
curl "https://fxmacrodata.com/api/v1/announcements/gbp/unemployment?api_key=YOUR_API_KEY"
{
"currency": "GBP",
"indicator": "unemployment",
"has_official_forecast": false,
"start_date": "2025-01-31",
"end_date": "2026-03-31",
"data": [
{
"date": "2026-01-31",
"val": 4.39,
"announcement_datetime": 1770521400
}
]
}
查看指标语义和单位的确切情况,请查看终点页面,如 美元政策利率 现在我 欧元通货膨胀现在我们要做什么?
步骤5 - 使用发布日历来实现事件驱动的工作流程
发布日历可以帮助您在发布时间安排取出, 而不是持续投票.
curl "https://fxmacrodata.com/api/v1/calendar/usd?indicator=non_farm_payrolls"
一个强大的模式是:查询日历 -> 阅读下一个 announcement_datetime -> 在发布时间取出匹配的公告路线.
步骤6 - 添加补充终点家族
您的核心广告流量稳定后, 扩展到特定域的路线:
- 其他
/api/v1/cot/{currency}对于期货定位的背景 - 金属:
/api/v1/commodities/{indicator}对于黄金,银,和相关的安全避难所投入 - 外国货币:
/api/v1/forex/{pair}对于与宏观发布的现场对齐 - 市场会议:
/api/v1/market-sessions对于会话状态自动化
curl "https://fxmacrodata.com/api/v1/cot/usd"
curl "https://fxmacrodata.com/api/v1/commodities/gold"
curl "https://fxmacrodata.com/api/v1/forex/eurusd"
curl "https://fxmacrodata.com/api/v1/market-sessions"
步骤7 - 一个端到端的Python示例
下面的片段检查可用性,获取一个指标系列,并返回最新的打印.
import requests
BASE = "https://fxmacrodata.com/api/v1"
API_KEY = "YOUR_API_KEY"
def fetch_latest(currency: str, indicator: str, api_key: str | None = None) -> dict | None:
params = {}
if api_key:
params["api_key"] = api_key
catalogue = requests.get(f"{BASE}/catalogue/{currency}", params=params, timeout=10)
catalogue.raise_for_status()
endpoint = requests.get(
f"{BASE}/announcements/{currency}/{indicator}",
params=params,
timeout=10,
)
endpoint.raise_for_status()
rows = endpoint.json().get("data", [])
return rows[-1] if rows else None
latest = fetch_latest("aud", "policy_rate", API_KEY)
print(latest)
您可以建立下一个
现在您有完整的路径来验证,发现覆盖范围,请求历史发布系列,并扩展到日历驱动的自动化. 如何使用发布日历API 所以当新宏观数据发布时,