เริ่มต้นใช้งานอย่างรวดเร็ว
เริ่มต้นใช้งานได้ในทุกภาษา
FXMacroData API คือ JSON REST API มาตรฐาน ภาษาใดก็ตามที่รองรับ HTTP สามารถใช้งานได้ เอนด์พอยต์ time-series แบบ freemium มีให้บริการสำหรับ 90 วันล่าสุดโดยไม่ต้องมีคีย์ เพิ่มคีย์ Individual API เพื่อปลดล็อกประวัติทั้งหมดและกลุ่มเอนด์พอยต์แบบชำระเงิน
ฐาน URL
https://api.fxmacrodata.com
การยืนยันตัวตน
X-API-Key: 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× payload ที่เล็กลง), ใช้ ETag ส่วนหัวการตอบกลับใน If-None-Match ในการดึงข้อมูลซ้ำ (คืนค่า 304 Not Modified โดยไม่มี body), และส่ง ?limit=50 ใน endpoint ของตัวชี้วัดเดี่ยว เช่น /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 วัตถุ สำหรับการทำ backtests และการรายงานระดับสถาบัน ให้ตรวจสอบ point_in_time_safe, has_announcement_datetime, source_type, และ is_stale.
การเรียกใช้ API ครั้งแรก
คำขอแบบด่วน
เริ่มต้นด้วย endpoint การประกาศแบบเรียลไทม์ การยืนยันตัวตนจะอยู่ใน api_key พารามิเตอร์การสอบถามสำหรับการทดสอบผ่านเบราว์เซอร์และสคริปต์โดยตรง
curl "https://api.fxmacrodata.com/v1/announcements/eur/inflation?api_key=YOUR_API_KEY"
คำขอ Python
คำขอ Python API ที่คัดลอกได้
ใช้ตัวอย่าง REST โดยตรงเหล่านี้เมื่อคุณต้องการคำขอ API แบบดิบแทนที่จะใช้ wrapper ของ SDK เปลี่ยน YOUR_API_KEY เฉพาะในเส้นทางที่ได้รับการป้องกันเท่านั้น
ฉันทามติของตลาดเงินเฟ้อ USD
การคาดการณ์จาก Consensus, ผลสำรวจ, ธนาคารกลาง, 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 inflation พร้อม timestamps ที่ทราบค่า
บันทึกเงินเฟ้อ USD สาธารณะสำหรับการทำ backtest แบบ point-in-time
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))
ประวัติ spot ของ 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
ประวัติการตัดสินใจของธนาคารกลางพร้อมเวลาการประกาศเพื่อการวิจัยแบบไม่มีการมองไปข้างหน้า (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))
กำหนดการประกาศที่กำลังจะมาถึงของ 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. ไคลเอนต์แบบ Sync และ async, ผลลัพธ์ที่พร้อมสำหรับ 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])
ไคลเอนต์แบบ Async
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 World Economic Outlook และการสำรวจผู้พยากรณ์มืออาชีพ การคาดการณ์จะถูกร้องขอสำหรับสกุลเงินและตัวบ่งชี้ที่เฉพาะเจาะจง เช่น https://api.fxmacrodata.com/v1/predictions/usd/inflation; ไม่รองรับการขอการคาดการณ์เฉพาะสกุลเงินเท่านั้น การคาดการณ์แต่ละรายการจะเชื่อมโยงกับการประกาศผ่าน announcement_id, เพื่อให้คุณสามารถรวมการพยากรณ์เข้ากับการสังเกตการณ์ที่เกิดขึ้นจริงได้
prediction_type="fxmacrodata" คือค่าประมาณที่สร้างโดย FXMacroData; ฉันทามติที่รวบรวมมาอย่างแท้จริงจะถูกระบุว่า market_consensus. ความพร้อมของการพยากรณ์แตกต่างกันไปตามการประกาศ — ตรวจสอบที่ เมทริกซ์การครอบคลุม. สำหรับการวิจัยที่ปราศจากการมองเห็นข้อมูลล่วงหน้า (look-ahead-free) ให้ปฏิบัติตาม คู่มือการทำ point-in-time backtesting.
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 | การพยากรณ์ระยะสั้น (nowcast) ตามแบบจำลองของธนาคารกลางหรือธนาคารสำรอง |
| การสำรวจ | การสำรวจนักพยากรณ์มืออาชีพของธนาคารกลาง (เช่น ECB SPF) |
| central_bank_forecast | การคาดการณ์อย่างเป็นทางการของธนาคารกลาง (เช่น RBNZ MPS, BoC MPR) |
| central_bank_projection | การคาดการณ์อย่างเป็นทางการจากธนาคารกลาง |
| imf_weo | การคาดการณ์ World Economic Outlook ของ 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 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());
ไป
ไม่จำเป็นต้องใช้แพ็กเกจภายนอก — standard library จัดการทุกอย่าง
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);
สร้าง typed client สำหรับภาษาใดก็ได้
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
พร้อมที่จะสร้างหรือยัง?
endpoints ของ USD รองรับการประเมินแบบไม่ใช้คีย์สูงสุด 100 ครั้ง/วัน สมัครสมาชิกเพื่อรับขีดจำกัดที่สูงขึ้นและการเข้าถึงหลายสกุลเงิน