Bắt đầu nhanh
Bắt đầu bằng bất kỳ ngôn ngữ nào
FXMacroData API là một JSON REST API tiêu chuẩn. Bất kỳ ngôn ngữ nào hỗ trợ HTTP đều hoạt động được. Các endpoint chuỗi thời gian freemium có sẵn cho 90 ngày gần nhất mà không cần khóa. Thêm khóa API Cá nhân để mở khóa toàn bộ lịch sử và các nhóm endpoint trả phí.
Cơ bản URL
https://api.fxmacrodata.com
Xác thực
X-API-Khóa: YOUR_API_KEY
Authorization: Bearer YOUR_API_KEY
?api_key=YOUR_API_KEY
Định dạng phản hồi
JSON (Content-Type: application/json)
openapi-generator-cli để tự động tạo các client bằng 40+ ngôn ngữ.
Accept-Encoding: gzip trên mỗi yêu cầu (8–12× payload nhỏ hơn), tái sử dụng ETag header phản hồi trong If-None-Match trong các cuộc thăm dò lặp lại (trả về 304 Not Modified không có thân bài), và truyền ?limit=50 về các endpoint chỉ số đơn lẻ như /v1/announcements/usd/inflation hoặc /v1/predictions/usd/inflation khi bạn chỉ cần các hàng gần đây nhất. Xem tham chiếu đầy đủ →
core_pce tồn tại cho USD nhưng không phải cho mọi loại tiền tệ. Liệt kê mọi slug mà một loại tiền tệ hỗ trợ với GET /v1/data_catalogue/{currency}, ví dụ /v1/data_catalogue/usd. Một 404 với error_code: NO_DATA_IN_REQUESTED_WINDOW nghĩa là slug hợp lệ và chỉ có cửa sổ ngày được yêu cầu là trống — mở rộng start_date/end_date thay vì thay đổi URL.
data_quality đối tượng. Đối với backtest và báo cáo tổ chức, hãy kiểm tra point_in_time_safe, has_announcement_datetime, source_type, và is_stale.
Cuộc gọi API đầu tiên
Yêu cầu Nhanh
Bắt đầu với một endpoint thông báo live. Xác thực nằm trong api_key tham số truy vấn để kiểm tra trực tiếp bằng trình duyệt và tập lệnh.
curl "https://api.fxmacrodata.com/v1/announcements/eur/inflation?api_key=YOUR_API_KEY"
Yêu cầu Python
Các yêu cầu API Python có thể sao chép
Sử dụng các ví dụ REST trực tiếp này khi bạn muốn yêu cầu API thô thay vì một trình bao bọc SDK. Chỉ thay thế YOUR_API_KEY trên các tuyến đường được bảo vệ.
sự đồng thuận thị trường lạm phát USD
Các dự báo đồng thuận, khảo sát, ngân hàng trung ương, IMF, và FXMacroData được kết nối với các thông báo thực tế.
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 lạm phát với các mốc thời gian đã biết
Hồ sơ lạm phát USD công khai cho các backtest tại một thời điểm.
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))
lịch sử giao ngay EUR/USD FX
Lịch sử giá FX hàng ngày cho biểu đồ cặp tiền, mô hình và lớp phủ phát hành.
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))
lịch sử lãi suất chính sách AUD
Lịch sử quyết định của Ngân hàng Trung ương với thời gian công bố để nghiên cứu không nhìn trước dữ liệu (no-lookahead).
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))
Lịch trình công bố sắp tới của JPY
Các sự kiện macro sắp tới với các trường UTC, địa phương thị trường và múi giờ được yêu cầu để lập kế hoạch cảnh báo, làm mới mô hình và đánh giá giao dịch.
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))
Giá hàng hóa Vàng
Chuỗi thời gian kim loại quý chính thức với các giá trị hàng ngày và trường thay đổi.
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
Cài đặt bản chính thức fxmacrodata gói từ PyPI. Các client đồng bộ và bất đồng bộ, đầu ra sẵn sàng cho pandas.
Sử dụng 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")
Sử dụng trực tiếp 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])
Client bất đồng bộ
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())
Dự báo & Dự báo
The /v1/predictions/{currency}/{indicator} endpoint cung cấp dữ liệu dự báo từ các khảo sát đồng thuận thị trường, dự báo của ngân hàng trung ương, Triển vọng Kinh tế Thế giới của IMF, và các khảo sát dự báo chuyên nghiệp. Các dự đoán được yêu cầu cho một loại tiền tệ và chỉ số cụ thể, chẳng hạn như https://api.fxmacrodata.com/v1/predictions/usd/inflation; các yêu cầu dự báo chỉ dành cho tiền tệ không được hỗ trợ. Mỗi dự báo được liên kết với thông báo của nó thông qua announcement_id, để bạn có thể kết hợp các dự báo với các quan sát thực tế.
prediction_type="fxmacrodata" là một ước tính do FXMacroData tạo ra; một sự đồng thuận biên soạn thực sự được dán nhãn là market_consensus. Khả năng cung cấp dự báo thay đổi theo bản công bố — hãy kiểm tra ma trận bao phủ. Để nghiên cứu không bị nhìn trước (look-ahead-free), hãy theo dõi hướng dẫn backtesting tại một thời điểm.
Python — truy xuất dự báo và kết hợp với thực tế
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 — lấy các dự báo theo loại
# 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"
Tham chiếu các loại dự đoán
| prediction_type | Mô tả |
|---|---|
| market_consensus | Đồng thuận sự kiện thị trường hoặc nhà kinh tế được biên soạn, nếu có |
| market_prediction | Dự báo điểm từ chuyên gia dự báo chuyên nghiệp |
| model_nowcast | Dự báo hiện tại (nowcast) theo mô hình ngân hàng trung ương hoặc ngân hàng dự trữ |
| khảo sát | Khảo sát của ngân hàng trung ương về các nhà dự báo chuyên nghiệp (ví dụ: ECB SPF) |
| central_bank_forecast | Dự báo chính thức của ngân hàng trung ương (ví dụ: RBNZ MPS, BoC MPR) |
| central_bank_projection | Dự báo chính thức của ngân hàng trung ương |
| imf_weo | Dự báo Triển vọng Kinh tế Thế giới của IMF |
| fxmacrodata | Dự đoán do FXMacroData tạo ra kết hợp hướng dẫn của ngân hàng trung ương, khảo sát và xu hướng lịch sử |
cURL
Không cần cài đặt. Hoạt động từ bất kỳ terminal nào.
# 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
Hoạt động trong Node.js (18+), Deno, Bun và các trình duyệt hiện đại với Fetch API.
npm client chính thức
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);
Sử dụng Fetch trực tiếp
// 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());
Đi
Không cần các gói bên ngoài — thư viện tiêu chuẩn sẽ xử lý mọi thứ.
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
Yêu cầu httr và 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
Sử dụng java.net.http (Java 11+). Không cần thư viện bên ngoài.
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
Sử dụng 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
Sử dụng tính năng tích hợp sẵn 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);
Tạo một client có kiểu dữ liệu cho bất kỳ ngôn ngữ nào
FXMacroData API xuất bản một bản hoàn chỉnh Thông số kỹ thuật OpenAPI 3.1. Sử dụng nó với openapi-generator để tạo các client được định kiểu đầy đủ cho Kotlin, Swift, Rust, Dart, Ruby, PHP, và 40+ các ngôn ngữ khác.
# 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
Sẵn sàng xây dựng?
Các endpoint USD hỗ trợ đánh giá không cần khóa lên đến 100 yêu cầu/ngày. Đăng ký để có hạn mức cao hơn và quyền truy cập đa tiền tệ.