FXMacroData は,現在,リアルタイム サーバー送信イベント (SSE) ストリームエンドポイントを提供しています. 一度接続すると,アプリケーションは,経済リリースが摂取された瞬間,すべての18のサポート通貨を含む,ライブプッシュ通知を受け取ります. 連邦準備制度理事会 政策決定 銀行 銀行からのデータです. 銀行から
ニュースは?
- オンライン配信 終了点
api.fxmacrodata.com/v1/stream/events - 無料プラン: USD 発表イベント,API キー不要
- プロプラン: 全18通貨,通貨と指標によってフィルタリング可能
- 自動心拍は 30秒ごとにプロキシで接続を保持します
- サポートを再生する
Last-Event-ID首頁 切断後に逃したイベントを再開
目的地
SSEストリームは,次の URL で利用できます.これは FXMacroData API サーバーへの直接接続です. 使わないで fxmacrodata.com/api/...
SSEへの経路応答をバッファリングし,ライブストリームを断ち切る.
https://api.fxmacrodata.com/v1/stream/events
選択可能なクエリパラメータでフィードを絞ることができます:
currencies引数で区切られたリスト:usd,eur,gbpindicators引数で区切られたリスト:inflation,policy_rateapi_keyドル以外の通貨でプロのAPIキーが必要
curl -N "https://api.fxmacrodata.com/v1/stream/events?currencies=usd&indicators=inflation,policy_rate"
イベント形式
公開された経済リリースごとに標準的なW3C イベントソースフレームワークが作成されます:
id: usd_inflation_1772109000
event: announcement
data: {"event_id": "usd_inflation_1772109000", "currency": "usd", "indicator": "inflation", "records_written": 1, "timestamp": 1772109002}
SSEメッセージは,完全なデータ・ペイロードではなく,運用誘発です.受信すると, API データ ドキュメント 新しい値を含む完全な時間列を取得します.
ブラウザの例
ブラウザで,ネイティブ EventSource 自動で再接続を処理します. 次の例は, 農地以外の賃金の表
ほら ドルインフレ 認証されていない無料層を使用:
const streamUrl = new URL("https://api.fxmacrodata.com/v1/stream/events");
streamUrl.searchParams.set("currencies", "usd");
streamUrl.searchParams.set("indicators", "non_farm_payrolls,inflation");
const source = new EventSource(streamUrl);
source.addEventListener("announcement", async (event) => {
const payload = JSON.parse(event.data);
console.log("Release received:", payload.currency, payload.indicator);
// Fetch the full record now that we know new data is available
const resp = await fetch(
`https://api.fxmacrodata.com/v1/announcements/${payload.currency}/${payload.indicator}`
);
const records = await resp.json();
console.log("Latest record:", records[records.length - 1]);
});
source.onerror = (err) => console.error("SSE error", err);
Python の例
サーバー側で働く人なら requests ストリーミングモードです
Last-Event-ID 再び接続して,見逃したイベントを再生します:
import json, time, requests
API_KEY = "YOUR_API_KEY"
STREAM_URL = (
"https://api.fxmacrodata.com/v1/stream/events"
"?currencies=usd,eur&indicators=inflation,policy_rate&api_key=" + API_KEY
)
def consume():
last_id = None
while True:
headers = {"Accept": "text/event-stream"}
if last_id:
headers["Last-Event-ID"] = last_id
try:
with requests.get(STREAM_URL, headers=headers, stream=True, timeout=90) as r:
r.raise_for_status()
event = {}
for line in r.iter_lines(decode_unicode=True):
if not line:
if event.get("event") == "announcement" and event.get("data"):
payload = json.loads(event["data"])
last_id = event.get("id") or payload["event_id"]
print("New release:", payload)
event = {}
continue
if not line.startswith(":"):
field, _, value = line.partition(":")
event[field] = value.lstrip()
except requests.RequestException as e:
print(f"Disconnected: {e}. Retrying...")
time.sleep(3)
consume()
プランの利用可能性
無料プラン
公開イベントのみ.APIキー不要.直接接続 api.fxmacrodata.com/v1/stream/events 認証パラメータがない
職業計画
すべての18通貨.通貨と指標の任意の組み合わせでフィルタリング. ?api_key=YOUR_KEY 検索文字列に
次は何を作るか
SSE ストリームは,既存の REST ワークフローの上でトリガー層として最もうまく機能します.実用的なパターンは以下の通りです:
- リアルタイムでダッシュボードカードの更新 — refresh one panel the moment new data arrives instead of polling every N minutes.
- 取引のアラート 最新リリースとあなたのスローリング値を比較して,すぐにSlackやwebhookの通知を起動します.
- キャッシュの無効化 更新された指標記録を再取得し,保存するための信号としてSSEイベントを使用します.
- 組み合わせると リリースカレンダー 次の予定を把握し,SSEが実際に公開する際にライブ確認として使用します.
ステップ・バイ・ステップの実施手順については, SSEの流通ガイドほら
FXマクロデータチーム