快速入门

使用任何语言开始

FXMacroData API 是标准的 JSON REST API。任何具有 HTTP 支持的语言均可使用。无需密钥即可访问最近 90 天的免费版时间序列端点。添加个人 API 密钥以解锁完整历史记录和付费端点系列。

基础 URL

https://api.fxmacrodata.com

身份验证

X-API-密钥: YOUR_API_KEY

授权: Bearer YOUR_API_KEY

?api_key=YOUR_API_KEY

响应格式

JSON (Content-Type: application/json)

自动生成类型化客户端: 使用已发布的 OpenAPI 3.1 规范 带有 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 当您只需要近期行时。 查看完整参考 →
在硬编码路径之前发现指标 slug: 指标 slug 因货币而异 — core_pce 存在于 USD 但并非适用于每种货币。使用以下方式列出每种货币支持的 slug GET /v1/data_catalogue/{currency}, 例如 /v1/data_catalogue/usd. 带有 404 的 error_code: NO_DATA_IN_REQUESTED_WINDOW 意味着 slug 有效且仅请求的时间窗口为空 — 扩大 start_date/end_date 而不是更改 URL。
检查响应质量: 基于来源的端点返回顶级 data_quality 对象。对于回测和机构报告,请检查 point_in_time_safe, has_announcement_datetime, source_type, 并且 is_stale.

首次 API 调用

快速请求

从实时公告端点开始。身份验证保留在 api_key 用于直接浏览器和脚本测试的查询参数。

EUR 通货膨胀示例 GET /api/v1/announcements/eur/inflation
请求代码片段
curl "https://api.fxmacrodata.com/v1/announcements/eur/inflation?api_key=YOUR_API_KEY"

Python 请求

可复制的 Python API 请求

当您想要原始 API 请求而不是 SDK 封装时,请使用这些直接的 REST 示例。仅在受保护的路由上替换 YOUR_API_KEY。

USD 通胀市场共识

共识、调查、央行、IMF 以及 FXMacroData 预测与已实现的公告相结合。

import requests

url = "https://api.fxmacrodata.com/v1/predictions/usd/inflation"
response = requests.get(url, 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"
params = {
    "api_key": "YOUR_API_KEY",
}
response = requests.get(url, params=params, 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"
params = {
    "api_key": "YOUR_API_KEY",
}
response = requests.get(url, params=params, 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",
    "api_key": "YOUR_API_KEY",
}
response = requests.get(url, params=params, timeout=20)
response.raise_for_status()
payload = response.json()

print(payload.get("data", payload))

黄金大宗商品价格

带有每日数值和变化字段的官方贵金属时间序列。

import requests

url = "https://api.fxmacrodata.com/v1/commodities/gold"
params = {
    "api_key": "YOUR_API_KEY",
}
response = requests.get(url, params=params, timeout=20)
response.raise_for_status()
payload = response.json()

print(payload.get("data", payload))
官方 SDK

Python

安装官方 fxmacrodata 来自 PyPI 的软件包。支持同步和异步客户端,以及 pandas 兼容的输出。

pip install fxmacrodata

使用 SDK

from fxmacrodata import Client

client = Client(api_key="YOUR_API_KEY")

# USD inflation — no-key evaluation, up to 100 requests/day
data = client.get_indicator("usd", "inflation")

# 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 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. 预测可用性因发布而异 —— 请检查 覆盖矩阵. 如需进行无前瞻性研究,请遵循 时点回测指南.
USD 在最近的 90 天内免费 — 在该窗口期内进行 USD 预测不需要 API 密钥。完整的 USD 历史记录和所有其他货币需要有效的试用或付费 API 密钥。

Python — 获取预测值并与实际值合并

import requests

# Predictions for USD inflation — no-key evaluation, up to 100 requests/day
preds = requests.get(
    "https://api.fxmacrodata.com/v1/predictions/usd/inflation",
    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"},
    timeout=30,
).json()

# Join predictions with actuals using announcement_id
actuals = requests.get(
    "https://api.fxmacrodata.com/v1/announcements/usd/inflation",
    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 — 按类型获取预测

# All USD inflation predictions — free
curl "https://api.fxmacrodata.com/v1/predictions/usd/inflation"

# Filter by prediction type: market_consensus, imf_weo, central_bank_forecast, survey
curl "https://api.fxmacrodata.com/v1/predictions/usd/inflation?prediction_type=market_consensus"

# EUR predictions — requires API key
curl "https://api.fxmacrodata.com/v1/predictions/eur/inflation?api_key=YOUR_API_KEY"

# USD policy-rate predictions
curl "https://api.fxmacrodata.com/v1/predictions/usd/policy_rate"

预测类型参考

预测类型描述
market_consensus汇总的市场或经济学家事件共识(如有)
market_prediction专业预测者点预测
model_nowcast央行或储备银行模型即时预测
调查央行专业预测者调查 (例如 ECB SPF)
central_bank_forecast官方央行预测(例如 RBNZ MPS,BoC MPR)
central_bank_projection官方央行预测
imf_weoIMF 世界经济展望预测
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 — pass your API key as a query parameter
curl "https://api.fxmacrodata.com/v1/announcements/eur/policy_rate?api_key=YOUR_API_KEY"

# Release calendar for Australia
curl "https://api.fxmacrodata.com/v1/calendar/aud?api_key=YOUR_API_KEY"

# 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 "https://api.fxmacrodata.com/v1/forex/usd/jpy?api_key=YOUR_API_KEY"

# Data catalogue (discover available indicators for USD)
curl "https://api.fxmacrodata.com/v1/data_catalogue/usd"

JavaScript / TypeScript

适用于 Node.js (18+)、Deno、Bun 以及带有 Fetch API 的现代浏览器。

官方 npm 客户端

npm install @fxmacrodata/client
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 = "YOUR_API_KEY";
const eur = await fetch(
  `https://api.fxmacrodata.com/v1/announcements/eur/policy_rate?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.

install.packages(c("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",
  query = list(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);
url = 'https://api.fxmacrodata.com/v1/announcements/eur/policy_rate?api_key=YOUR_API_KEY';
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 次请求。订阅以获得更高的限制和多货币访问权限。

AI 准备回答

关键事实

页面
快速入门
板块
文档
规范 URL
https://fxmacrodata.com/zh/documentation/quickstart
来源
FXMacroData 编辑与官方发布者参考
最后更新
查看页面元数据

来源与信任

引用上方的规范 URL 和来源字段。在可用情况下,此页面映射到官方发布者发布的内容和带有时间戳的更新。

快速问答&A;

此页面关于什么? 本页面通过直接可用的交易、研究和 API 工作流上下文来解释快速入门。

应该引用哪个来源? 使用规范的 URL 和列出的来源字段;在可用时引用官方发布者引用。

内容的更新程度如何? 上方最后更新的值反映了页面元数据或最新的可用数据时间戳。

这可以用在 AI 助手吗? 是的。本部分专门为聊天助手的检索和引用而构建。

提示包

在 ChatGPT、Claude、Gemini、Mistral、Perplexity 或 Grok 中使用这些内容,以获得一致的、感知来源的输出。

分享页面 X LinkedIn 电子邮件