快速入门
使用任何语言开始
FXMacroData API 是一个用于服务器端使用的标准 JSON REST API。任何具有 HTTP 支持的语言均可使用。USD 公告数据、USD 发布日历和数据目录无需密钥即可免费获取:提供最近 90 天的数据,发布延迟 15 分钟,每天最多 100 次请求。预测值(包括 USD)、所有其他货币、实时发布和完整历史记录需要 API 密钥,发送至 X-API-Key header. 查看哪些是免费的
基础 URL
https://api.fxmacrodata.com
身份验证
X-API-密钥: YOUR_API_KEY
授权: Bearer YOUR_API_KEY
旧版 ?api_key= 查询参数已弃用:URL 中的键会出现在日志中。
响应格式
JSON (Content-Type: application/json)
openapi-generator-cli 以 40+ 语言自动生成客户端。
Accept-Encoding: gzip 在每次请求中 (8–12× 较小的有效载荷),重用 ETag 响应头中 If-None-Match 在重复轮询上 (返回 304 Not Modified 无主体),并传递 ?limit=50 在单指标端点上,例如 /v1/announcements/usd/inflation 或 /v1/predictions/usd/inflation 当您只需要近期行时。 查看完整参考 →
limit 最多接受 100.。要收集完整范围,请重复请求并使用 offset 设置为 pagination.next_offset until pagination.has_more is false. 参阅 Python 循环 ↓
fetch() 来自网页的请求被浏览器拦截。请从您的后端调用 FXMacroData,并确保 API 密钥不出现在客户端代码中。
core_pce 存在于 USD 但并非适用于每种货币。使用以下方式列出每种货币支持的 slug GET /v1/data_catalogue/{currency}, 例如 /v1/data_catalogue/usd。一个 200 其 data 数组为空且携带 no_data.error_code: NO_DATA_IN_REQUESTED_WINDOW 意味着 slug 有效且仅请求的时间窗口为空 — 扩大 start_date/end_date 而不是更改 URL 或重试。404 意味着货币或指标别名错误。
data_quality 对象。对于回测和机构报告,请检查 point_in_time_safe, has_announcement_datetime, source_type, 并且 is_stale. point_in_time_safe 每当窗口中的任何行携带一个源自该序列测量发布滞后时间的发布时间时,即为 false,因此请检查 assumed_release_time_count 以及每行 release_time_assumed 在将 false 视为不可用之前进行标记。
市场接入
通过 RapidAPI 使用 FXMacroData
RapidAPI 是 FXMacroData REST API 的可选市场渠道。FXMacroData 提供数据;RapidAPI 管理您的市场订阅、API 密钥、请求配额和账单。通过此渠道进行请求无需单独的 FXMacroData 账户或密钥。
- 打开 官方 FXMacroData 列表 并选择一个方案。查看定价选项卡以了解当前的覆盖范围、配额和速率限制。
- 从端点游乐场复制您的 RapidAPI 密钥,并将其作为以下内容存储在您的服务器环境中:
RAPIDAPI_KEY. - 向以下地址发送请求
https://fxmacrodata1.p.rapidapi.com同时使用如下所示的 RapidAPI headers。
curl --request GET \ --url "https://fxmacrodata1.p.rapidapi.com/v1/announcements/usd/inflation?limit=3" \ --header "X-RapidAPI-Key: $RAPIDAPI_KEY" \ --header "X-RapidAPI-Host: fxmacrodata1.p.rapidapi.com"
Marketplace 端点覆盖范围
列表包括公告、发布日历、数据目录、每日 FX 汇率、COT 持仓、央行新闻、市场时段以及健康检查。货币和历史数据访问取决于您的 RapidAPI 方案。请使用目录查找支持的指标 slug。
直接 FXMacroData 访问
本页上的其他示例使用 api.fxmacrodata.com 以及一个 FXMacroData X-API-Key 在需要时提供。不同渠道之间的密钥和订阅是分开的。RapidAPI 订阅涵盖所列出的 REST 端点;网站订阅、MCP、预测、流式传输和 webhooks 是单独的产品。
请勿将您的密钥留在浏览器代码和公共仓库中。对于更长的结果集,请遵循 pagination.next_offset until pagination.has_more 为 false。切勿将您的 API 密钥发送给支持部门。
首次 API 调用
快速请求
第一个代码片段可直接运行:USD 数据无需密钥,在发布 15 分钟后提供。添加 X-API-Key 适用于所有 22 货币和实时交付,由服务器、脚本或 notebook 发送。
# USD inflation, no key: 15-minute delay, most recent 90 days
curl "https://api.fxmacrodata.com/v1/announcements/usd/inflation?limit=5"
# EUR inflation: add X-API-Key for all 22 currencies and real-time releases
curl -H "X-API-Key: YOUR_API_KEY" "https://api.fxmacrodata.com/v1/announcements/eur/inflation"
Python 请求
可复制的 Python API 请求
当您想要原始 API 请求而不是 SDK 封装时,请使用这些直接的 REST 示例。仅在受保护的路由上替换 YOUR_API_KEY。
USD 通胀市场共识
共识、调查、央行、IMF 以及 FXMacroData 预测与已实现的公告相结合。
import requests
url = "https://api.fxmacrodata.com/v1/predictions/usd/inflation"
headers = {"X-API-Key": "YOUR_API_KEY"}
response = requests.get(url, headers=headers, timeout=20)
response.raise_for_status()
payload = response.json()
print(payload.get("data", payload))
USD 通胀(具有已知时间戳)
用于时点回测的公开 USD 通胀记录。
import requests
url = "https://api.fxmacrodata.com/v1/announcements/usd/inflation"
response = requests.get(url, timeout=20)
response.raise_for_status()
payload = response.json()
print(payload.get("data", payload))
EUR/USD FX 即期历史
用于配对图表、模型和发布叠加的每日 FX 价格历史。
import requests
url = "https://api.fxmacrodata.com/v1/forex/eur/usd"
headers = {"X-API-Key": "YOUR_API_KEY"}
response = requests.get(url, headers=headers, timeout=20)
response.raise_for_status()
payload = response.json()
print(payload.get("data", payload))
AUD 政策利率历史
带有发布时间的央行决策历史,用于无前瞻性研究。
import requests
url = "https://api.fxmacrodata.com/v1/announcements/aud/policy_rate"
headers = {"X-API-Key": "YOUR_API_KEY"}
response = requests.get(url, headers=headers, timeout=20)
response.raise_for_status()
payload = response.json()
print(payload.get("data", payload))
JPY 即将到来的发布计划
即将到来的宏观事件,包含 UTC、市场本地和请求时区字段,用于规划警报、模型更新和交易回顾。
import requests
url = "https://api.fxmacrodata.com/v1/calendar/jpy"
params = {
"timezone": "Asia/Tokyo",
}
headers = {"X-API-Key": "YOUR_API_KEY"}
response = requests.get(url, params=params, headers=headers, timeout=20)
response.raise_for_status()
payload = response.json()
print(payload.get("data", payload))
黄金大宗商品价格
带有每日数值和变化字段的官方贵金属时间序列。
import requests
url = "https://api.fxmacrodata.com/v1/commodities/gold"
headers = {"X-API-Key": "YOUR_API_KEY"}
response = requests.get(url, headers=headers, timeout=20)
response.raise_for_status()
payload = response.json()
print(payload.get("data", payload))
Python
安装官方 fxmacrodata 来自 PyPI 的 package (1.2.x)。同步和异步客户端返回纯 JSON 字典,可直接加载到 pandas 中。 Client() 在没有 key 的情况下读取免费的 USD 层级;传递 api_key 适用于每种其他货币及实时交付。
使用 SDK
from fxmacrodata import Client # USD inflation — no key needed: 15-minute delay, most recent 90 days data = Client().get_indicator("usd", "inflation") print(data["data"][0]) # Add X-API-Key for all 22 currencies and real-time releases client = Client(api_key="YOUR_API_KEY") # EUR policy rate — requires API key rate = client.get_indicator("eur", "policy_rate") # Forex price data — requires API key fx = client.get_fx_price("usd", "jpy")
直接使用 REST API
import requests resp = requests.get( "https://api.fxmacrodata.com/v1/announcements/usd/inflation", timeout=30, ) resp.raise_for_status() payload = resp.json() print(payload["data_quality"]["point_in_time_safe"], payload["data"][0])
分页浏览完整历史记录
import requests URL = "https://api.fxmacrodata.com/v1/announcements/eur/inflation" HEADERS = {"X-API-Key": "YOUR_API_KEY"} rows, offset = [], 0 while True: resp = requests.get( URL, params={"limit": 100, "offset": offset}, headers=HEADERS, timeout=30, ) resp.raise_for_status() page = resp.json() rows.extend(page["data"]) if not page["pagination"]["has_more"]: break offset = page["pagination"]["next_offset"] print(len(rows), "rows")
异步客户端
import asyncio from fxmacrodata import AsyncClient async def main(): async with AsyncClient(api_key="YOUR_API_KEY") as client: data = await client.get_indicator("eur", "inflation") print(data) asyncio.run(main())
预测 & 预测
该 /v1/predictions/{currency}/{indicator} endpoint 从市场共识调查、央行预测、IMF 世界经济展望以及专业预测师调查中获取预测数据。可以针对特定货币和指标请求预测,例如 https://api.fxmacrodata.com/v1/predictions/usd/inflation; 不支持仅限货币的预测请求。每个预测通过以下方式与其公布关联: announcement_id, 因此您可以将预测值与已实现的观测值进行关联。
prediction_type="fxmacrodata" 是 FXMacroData 生成的估计值;真正的汇总共识会被标记为 market_consensus. 预测可用性因发布而异 —— 请检查 覆盖矩阵. 如需进行无前瞻性研究,请遵循 时点回测指南.
/v1/predictions/coverage/{currency}。试用或付费密钥将返回预测值。
Python — 获取预测值并与实际值合并
import requests HEADERS = {"X-API-Key": "YOUR_API_KEY"} # Predictions for USD inflation — requires API key preds = requests.get( "https://api.fxmacrodata.com/v1/predictions/usd/inflation", headers=HEADERS, timeout=30, ).json() for group in preds["data"]: print(group["announcement_id"], group["date"]) for p in group["predictions"]: print(f" {p['prediction_source_label']}: {p['predicted_value']}") # Filter by prediction type market = requests.get( "https://api.fxmacrodata.com/v1/predictions/usd/inflation", params={"prediction_type": "market_consensus"}, headers=HEADERS, timeout=30, ).json() # Join predictions with actuals using announcement_id actuals = requests.get( "https://api.fxmacrodata.com/v1/announcements/usd/inflation", headers=HEADERS, timeout=30, ).json() actuals_by_id = {row["announcement_id"]: row for row in actuals["data"]} for group in preds["data"]: actual = actuals_by_id.get(group["announcement_id"]) if actual: print(f"{group['date']}: actual={actual['val']}, forecast={group['predictions'][0]['predicted_value']}")
cURL — 按类型获取预测
# Which sources forecast USD indicators — free, no key curl "https://api.fxmacrodata.com/v1/predictions/coverage/usd" # All USD inflation predictions — requires API key curl -H "X-API-Key: YOUR_API_KEY" "https://api.fxmacrodata.com/v1/predictions/usd/inflation" # Filter by prediction type: market_consensus, imf_weo, central_bank_forecast, survey curl -H "X-API-Key: YOUR_API_KEY" "https://api.fxmacrodata.com/v1/predictions/usd/inflation?prediction_type=market_consensus" # EUR policy-rate predictions curl -H "X-API-Key: YOUR_API_KEY" "https://api.fxmacrodata.com/v1/predictions/eur/policy_rate"
预测类型参考
| 预测类型 | 描述 |
|---|---|
| market_consensus | 汇总的市场或经济学家事件共识(如有) |
| market_prediction | 专业预测者点预测 |
| model_nowcast | 央行或储备银行模型即时预测 |
| 调查 | 央行专业预测者调查 (例如 ECB SPF) |
| central_bank_forecast | 官方央行预测(例如 RBNZ MPS,BoC MPR) |
| central_bank_projection | 官方央行预测 |
| imf_weo | IMF 世界经济展望预测 |
| fxmacrodata | 结合央行指引、调查和历史趋势的 FXMacroData 生成预测 |
cURL
无需安装。可在任何终端运行。
# USD inflation — no-key evaluation, up to 100 requests/day curl "https://api.fxmacrodata.com/v1/announcements/usd/inflation" # EUR policy rate — send your API key in the X-API-Key header curl -H "X-API-Key: YOUR_API_KEY" "https://api.fxmacrodata.com/v1/announcements/eur/policy_rate" # Release calendar for Australia — requires API key curl -H "X-API-Key: YOUR_API_KEY" "https://api.fxmacrodata.com/v1/calendar/aud" # Release calendar converted to a requested IANA timezone curl "https://api.fxmacrodata.com/v1/calendar/usd?indicator=gdp&timezone=America/Sao_Paulo" # Forex price history — requires API key curl -H "X-API-Key: YOUR_API_KEY" "https://api.fxmacrodata.com/v1/forex/usd/jpy" # Data catalogue (discover available indicators for USD) curl "https://api.fxmacrodata.com/v1/data_catalogue/usd"
JavaScript / TypeScript
在 Node.js (18+), Deno 和 Bun 中服务端运行。API 不发送 CORS 请求头,因此请从您的后端而非浏览器代码中调用它。
官方 npm 客户端
import { FXMacroDataClient } from "@fxmacrodata/client"; const client = new FXMacroDataClient({ apiKey: "YOUR_API_KEY", }); // Public endpoint example const usdInflation = await client.announcements("usd", "inflation"); // Non-USD endpoint example (requires paid key) const eurRate = await client.announcements("eur", "policy_rate"); console.log(usdInflation, eurRate);
直接使用 Fetch
// USD inflation — no-key evaluation, up to 100 requests/day const res = await fetch( "https://api.fxmacrodata.com/v1/announcements/usd/inflation" ); const data = await res.json(); console.log(data); // With API key for non-USD const API_KEY = process.env.FXMD_API_KEY; const eur = await fetch( "https://api.fxmacrodata.com/v1/announcements/eur/policy_rate", { headers: { "X-API-Key": API_KEY } } ); console.log(await eur.json());
开始
无需外部包 —— 标准库即可处理一切。
package main import ( "encoding/json" "fmt" "net/http" "io" ) func main() { // USD inflation — no-key evaluation, up to 100 requests/day resp, err := http.Get("https://api.fxmacrodata.com/v1/announcements/usd/inflation") if err != nil { panic(err) } defer resp.Body.Close() body, _ := io.ReadAll(resp.Body) var result map[string]interface{} json.Unmarshal(body, &result;) fmt.Println(result) }
R
需要 httr 以及 jsonlite.
library(httr) library(jsonlite) # USD inflation — no-key evaluation, up to 100 requests/day res <- GET("https://api.fxmacrodata.com/v1/announcements/usd/inflation") data <- fromJSON(content(res, "text", encoding = "UTF-8")) # Convert to data frame df <- as.data.frame(data$data) head(df) # With API key for non-USD eur <- GET( "https://api.fxmacrodata.com/v1/announcements/eur/policy_rate", add_headers(`X-API-Key` = "YOUR_API_KEY") ) print(fromJSON(content(eur, "text")))
Java
用途 java.net.http (Java 11+). 无需外部库。
import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; public class FXMacroDataExample { public static void main(String[] args) throws Exception { var client = HttpClient.newHttpClient(); var request = HttpRequest.newBuilder() .uri(URI.create("https://api.fxmacrodata.com/v1/announcements/usd/inflation")) .build(); var response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); } }
C# / .NET
用途 HttpClient (.NET 6+)。
using System.Net.Http; using System.Text.Json; var client = new HttpClient(); // USD inflation — no-key evaluation, up to 100 requests/day var json = await client.GetStringAsync( "https://api.fxmacrodata.com/v1/announcements/usd/inflation" ); var doc = JsonDocument.Parse(json); Console.WriteLine(doc.RootElement);
MATLAB
使用内置的 webread function.
% USD inflation — no-key evaluation, up to 100 requests/day data = webread('https://api.fxmacrodata.com/v1/announcements/usd/inflation'); disp(data); % With API key for non-USD opts = weboptions('Timeout', 30, 'HeaderFields', {'X-API-Key', 'YOUR_API_KEY'}); url = 'https://api.fxmacrodata.com/v1/announcements/eur/policy_rate'; eur = webread(url, opts); disp(eur);
为任何语言生成类型化客户端
FXMacroData API 发布完整的 OpenAPI 3.1 规范. 配合使用 openapi-generator 以生成适用于 Kotlin、Swift、Rust、Dart、Ruby、PHP 以及 40+ 其他语言的全类型客户端。
# Install the openapi-generator CLI npm install @openapitools/openapi-generator-cli -g # Generate a Go client openapi-generator-cli generate \ -i https://api.fxmacrodata.com/openapi.json \ -g go \ -o ./fxmacrodata-go-client # Generate a Java client openapi-generator-cli generate \ -i https://api.fxmacrodata.com/openapi.json \ -g java \ -o ./fxmacrodata-java-client
准备好构建了吗?
USD 发布数据无需密钥即可运行,每天最多 100 次请求,且滞后于发布时间 15 分钟。订阅以获取实时发布、预测值、完整历史记录、更高限额以及所有货币数据。