快速入門
使用任何語言開始
FXMacroData API 是一個標準的 JSON REST API。任何支持 HTTP 的語言均可使用。無需金鑰即可訪問最近 90 天的免費時間序列端點。添加個人 API 金鑰以解鎖完整歷史記錄和付費端點系列。
基礎 URL
https://api.fxmacrodata.com
身份驗證
X-API-金鑰: YOUR_API_KEY
Authorization: Bearer YOUR_API_KEY
?api_key=YOUR_API_KEY
響應格式
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 當您只需要最近的行時。 查看完整參考資料 →
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 用於直接瀏覽器和腳本測試的查詢參數。
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))
帶有 known-at 時間戳的 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))
Python
安裝官方 fxmacrodata 來自 PyPI 的封裝包。同步和異步客戶端,pandas 就緒輸出。
使用 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} 端點提供來自市場共識調查、央行預測、IMF 世界經濟展望和專業預測者調查的預測數據。預測是針對特定貨幣和指標請求的,例如 https://api.fxmacrodata.com/v1/predictions/usd/inflation;不支持僅限貨幣的預測請求。每個預測都通過以下方式與其公布內容連結 announcement_id,因此您可以將預測與實際觀測值結合。
prediction_type="fxmacrodata" 是 FXMacroData 生成的估計值;真正的編譯共識標記為 market_consensus。預測可用性因發佈而異 — 請檢查 覆蓋矩陣。為了進行無前瞻偏差的研究,請遵循 時點回測指南.
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"
預測類型參考
| prediction_type | 描述 |
|---|---|
| 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 — 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 客戶端
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.
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 函數。
% 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 次請求/天的無金鑰評估。訂閱以獲取更高限制和多貨幣訪問權限。