このガイドの終わりまでに,次のリリースを見つけるために生産FXMacroDataのリリースカレンダーを使用するスケジューラーを持つでしょう. announcement_datetime 新たに印刷される予定の時刻を正確に呼び出す.
条件
- ほら FXMacroData API キーを ドル以外の通貨では,ドルスケジューリングは公開されます.
- Python 3.9+ または Node.js 18+
- ほら
requestsPython の例 の パッケージ - Unix のタイムスタンプ と UTC のスケジューリング に 基礎 的 な 熟知
なぜ投票ではなくスケジュール?
数分ごとに投票は簡単ですが,リクエストを無駄にし,正確なリリース秒の周りに回避可能な遅れを導入します. 生産カレンダーのエンドポイントは,次の予定された公開時間を直接提供します.
基本ワークフロー
- 呼び出し
/api/v1/calendar/{currency}選択してくださいindicatorフィルター - 次の列の文字を読んで
announcement_datetimeわかった - UTCタイムスタンプ直前まで寝て
- 持ってきて
/api/v1/announcements/{currency}/{indicator}わかった - 戻った人の最新報告を読む
data次のイベントをスケジュールします
ステップ 1 - カレンダーの応答を理解する
リリースカレンダーは JSON オブジェクトを返します. data 各行にはリリーススラグと予定された UTCタイムスタンプが含まれます.
curl "https://fxmacrodata.com/api/v1/calendar/usd?indicator=inflation"
応答形状:
{
"currency": "USD",
"indicator": "inflation",
"data": [
{
"announcement_datetime": 1773077400,
"release": "inflation"
}
]
}
ドル以外の通貨では,同じ経路を維持し,追加します api_key 指示フィルターなしでより広い通貨スケジュールをクエリする場合は,いくつかの行には,ルーティングメタデータも含まれます. endpoint_family ほら endpoint_pathほら
ステップ2 次のリリースタイムスタンプを見つけ
下のヘルパーは,単一の指標の生産カレンダーを求め,最初の将来のタイムスタンプを返します.
import time
import requests
BASE = "https://fxmacrodata.com/api/v1"
def next_release(currency: str, indicator: str, api_key: str | None = None) -> float | None:
url = f"{BASE}/calendar/{currency}"
params = {"indicator": indicator}
if api_key:
params["api_key"] = api_key
response = requests.get(url, params=params, timeout=10)
response.raise_for_status()
now = time.time()
for row in response.json().get("data", []):
ts = row.get("announcement_datetime")
if row.get("release") == indicator and ts and float(ts) > now:
return float(ts)
return None
ステップ3 - 公開されたデータを適切なタイミングで取得
返信から最新の観測を読み取ります 返却されたデータから最新の観察を読み取れます data 配列
def wait_and_fetch(currency: str, indicator: str, api_key: str | None = None) -> dict | None:
release_ts = next_release(currency, indicator, api_key)
if release_ts is None:
print(f"No upcoming release found for {currency}/{indicator}.")
return None
wake_at = release_ts - 2
time.sleep(max(0.0, wake_at - time.time()))
url = f"{BASE}/announcements/{currency}/{indicator}"
params = {"api_key": api_key} if api_key else {}
response = requests.get(url, params=params, timeout=10)
response.raise_for_status()
return response.json()
ステップ4 - 連続ループを構築する
import time
import requests
BASE = "https://fxmacrodata.com/api/v1"
API_KEY = None
CURRENCY = "usd"
INDICATOR = "inflation"
def on_release(payload: dict) -> None:
rows = payload.get("data", [])
latest = rows[-1] if rows else {}
print(
"New release:",
latest.get("date"),
"value=", latest.get("val"),
"announced_at=", latest.get("announcement_datetime"),
)
while True:
release_ts = next_release(CURRENCY, INDICATOR, API_KEY)
if release_ts is None:
print("No release found in the current calendar window. Retrying in 24 hours.")
time.sleep(86_400)
continue
sleep_seconds = max(0.0, release_ts - 2 - time.time())
print(f"Next {CURRENCY.upper()} {INDICATOR} release in {sleep_seconds / 3600:.2f}h")
time.sleep(sleep_seconds)
payload = wait_and_fetch(CURRENCY, INDICATOR, API_KEY)
if payload:
on_release(payload)
time.sleep(5)
リリース後の短い休止は,次のカレンダークエリの前に予定されたイベントを前方にロールするシステムに時間を与えます.
ステップ5 - 複数の時計にスケール
To follow several indicators, run one scheduler per pair. Use canonical indicator slugs throughout so the calendar and announcements routes stay aligned.
WATCHES = [
{"currency": "usd", "indicator": "inflation"},
{"currency": "usd", "indicator": "gdp"},
{"currency": "aud", "indicator": "policy_rate"},
{"currency": "gbp", "indicator": "unemployment"},
]
フォローアップの取材に関する詳細については, AUD 政策金利ほら GBPの失業率発表のドキュメントのインデックス.
ステップ6 - JavaScript / Node.js バリアント
指示フィルターでカレンダーに問い合わせ,返したタイムスタンプまで休憩,その後マッチングの通知ルートを取得します.
const BASE = "https://fxmacrodata.com/api/v1";
async function nextRelease(currency, indicator, apiKey) {
const url = new URL(`${BASE}/calendar/${currency}`);
url.searchParams.set("indicator", indicator);
if (apiKey) url.searchParams.set("api_key", apiKey);
const response = await fetch(url);
if (!response.ok) throw new Error(`Calendar request failed: ${response.status}`);
const payload = await response.json();
const now = Date.now() / 1000;
return payload.data.find((row) => row.release === indicator && row.announcement_datetime > now) ?? null;
}
async function fetchAnnouncement(currency, indicator, apiKey) {
const url = new URL(`${BASE}/announcements/${currency}/${indicator}`);
if (apiKey) url.searchParams.set("api_key", apiKey);
const response = await fetch(url);
if (!response.ok) throw new Error(`Announcement request failed: ${response.status}`);
return response.json();
}
If you need to support a queue, cron worker, or serverless timer, keep the same two-step pattern: calendar for timing, announcements for values.