快速入門
使用任何語言開始
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
Authorization: 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 在將錯誤視為不可用之前進行標記。
市場存取
使用 FXMacroData 至 RapidAPI
RapidAPI 是 FXMacroData REST API 的選用市場通路。FXMacroData 提供數據;RapidAPI 管理您的市場訂閱、API 金鑰、請求配額與結算。透過此通路進行請求時,不需要額外的 FXMacroData 帳戶或金鑰。
- 打開 官方 FXMacroData 列名 並選擇方案。請查看定價分頁以了解目前的涵蓋範圍、配額與速率限制。
- 從端點遊樂場複製您的 RapidAPI 金鑰,並將其作為以下內容儲存在您的伺服器環境中:
RAPIDAPI_KEY. - 向以下地址發送請求
https://fxmacrodata1.p.rapidapi.com同時使用 RapidAPI 標頭,如下所示。
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"
市場端點覆蓋範圍
列表包括公告、發布日曆、數據目錄、每日 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 貨幣與即時傳輸,可從伺服器、腳本或筆記本發送。
# 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))
帶有 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"
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 的套件 (1.2.x)。同步與非同步用戶端會回傳純 JSON 字典,可直接載入至 pandas。 Client() 若無金鑰讀取則使用免費的 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} 端點提供來自市場共識調查、央行預測、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"
預測類型參考
| 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 — 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 函數。
% 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 分鐘。訂閱以獲取即時發佈、預測值、完整歷史記錄、更高限制以及所有貨幣。