Hurtigstart
Kom i gang på ethvert sprog
FXMacroData API er en standard JSON REST API. Ethvert sprog med HTTP support fungerer. Freemium tidsserie-endpoints er tilgængelige for de seneste 90 dage uden en nøgle. Tilføj en Individual API nøgle for at låse op for fuld historik og betalte endpoint-familier.
Basis-URL
https://api.fxmacrodata.com
Autentificering
X-API-Nøgle: YOUR_API_KEY
Authorization: Bearer YOUR_API_KEY
?api_key=YOUR_API_KEY
Responformat
JSON (Content-Type: application/json)
openapi-generator-cli til automatisk at generere klienter i 40+ sprog.
Accept-Encoding: gzip på hver anmodning (8–12× mindre payloads), genbrug ETag responshoved i If-None-Match ved gentagne afstemninger (returnerer 304 Not Modified uden body), og overfør ?limit=50 på enkelt-indikator endpoints såsom /v1/announcements/usd/inflation eller /v1/predictions/usd/inflation når du kun har brug for nyere rækker. Se den fulde reference →
core_pce eksisterer for USD, men ikke for alle valutaer. List hver slug, en valuta understøtter med GET /v1/data_catalogue/{currency}, for eksempel /v1/data_catalogue/usd. En 404 med error_code: NO_DATA_IN_REQUESTED_WINDOW betyder at sluggen er gyldig, og kun det anmodede datovindue er tomt — udvide start_date/end_date frem for at ændre URL.
data_quality objekt. For backtests og institutionel rapportering, inspicer point_in_time_safe, has_announcement_datetime, source_type, og is_stale.
Første API kald
Hurtig anmodning
Start med et live meddelelses-endpoint. Autentificering forbliver i api_key forespørgselsparameter til direkte browser- og script-test.
curl "https://api.fxmacrodata.com/v1/announcements/eur/inflation?api_key=YOUR_API_KEY"
Python anmodninger
Kopierbare Python API anmodninger
Brug disse direkte REST eksempler, når du ønsker den rå API anmodning i stedet for en SDK wrapper. Erstat kun YOUR_API_KEY på beskyttede ruter.
USD inflationsmarkedskonsensus
Konsensus, undersøgelse, centralbank, IMF og FXMacroData-prognoser koblet til realiserede meddelelser.
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 med known-at tidsstempler
Offentlige USD inflationsoptegnelser til point-in-time backtests.
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 spot-historik
Daglig FX prishistorik til par-diagrammer, modeller og release-overlays.
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 policy-rate historik
Centralbank-beslutningshistorik med udgivelsestidspunkt for forskning uden 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 kommende udgivelsesplan
Kommende makro-events med UTC, markedslokale og anmodede tidszone-felter til planlægning af alerts, modelopdateringer og trading-gennemgange.
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))
Guld råvarepriser
Officielle ædelmetal-tidsserier med daglige værdier og ændringsfelter.
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
Installer den officielle fxmacrodata pakke fra PyPI. Sync og async klienter, pandas-klar output.
Brug af 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")
Brug af REST API direkte
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-klient
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())
Forudsigelser & Prognoser
Den /v1/predictions/{currency}/{indicator} endpoint overflader prognosedata fra markedskonsensus-undersøgelser, centralbank-projektioner, IMF World Economic Outlook og professionelle prognose-undersøgelser. Forudsigelser anmodes for en specifik valuta og indikator, såsom https://api.fxmacrodata.com/v1/predictions/usd/inflation; anmodninger om kun-valuta-forudsigelser understøttes ikke. Hver forudsigelse er linket til sin annoncering via announcement_id, så du kan sammenkøre prognoser med realiserede observationer.
prediction_type="fxmacrodata" er et FXMacroData-genereret estimat; en sand sammenstillet konsensus er markeret market_consensus. Prognosetilgængelighed varierer efter udgivelse — tjek dækningsmatrix. For forskning uden look-ahead, følg guide til point-in-time backtesting.
Python — hent prognoser og sammenkør med faktiske tal
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 — hent forudsigelser efter type
# 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"
Reference for prædiktionstyper
| prediction_type | Beskrivelse |
|---|---|
| market_consensus | Kompileret marked- eller økonom-konsensus, hvor tilgængelig |
| market_prediction | Professionel prognose-punktforudsigelse |
| model_nowcast | Centralbank- eller reservebankmodel nowcast |
| undersøgelse | Centralbankundersøgelse af professionelle prognoseeksperter (f.eks. ECB SPF) |
| central_bank_forecast | Officiel centralbank-projektion (f.eks. RBNZ MPS, BoC MPR) |
| central_bank_projection | Officiel centralbank-fremskrivning |
| imf_weo | IMF World Economic Outlook projektion |
| fxmacrodata | FXMacroData-genereret forudsigelse, der kombinerer centralbank-vejledning, undersøgelser og historiske tendenser |
cURL
Ingen installation nødvendig. Virker fra enhver terminal.
# 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
Fungerer i Node.js (18+), Deno, Bun og moderne browsere med Fetch API.
Officiel npm klient
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);
Brug af Fetch direkte
// 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());
Gå
Ingen eksterne pakker nødvendige — standardbiblioteket håndterer alt.
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
Kræver httr og 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
Anvendelser java.net.http (Java 11+). Ingen eksterne biblioteker er nødvendige.
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
Anvendelser 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
Bruger den indbyggede webread funktion.
% 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);
Generer en typet klient til ethvert sprog
FXMacroData API udgiver en komplet OpenAPI 3.1 specifikation. Brug det med openapi-generator for at producere fuldt typede klienter til Kotlin, Swift, Rust, Dart, Ruby, PHP, og 40+ andre sprog.
# 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
Klar til at bygge?
USD endpoints understøtter nøgleløs evaluering op til 100 anmodninger/dag. Abonner for højere grænser og adgang til flere valutaer.