Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions examples/FXMacroData_Calendar/fxmacrodata_calendar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""FXMacroData release-calendar helper for forex backtest examples."""

import json
from datetime import date, timedelta
from urllib.parse import urlencode
from urllib.request import urlopen


BASE_URL = "https://fxmacrodata.com/api/v1/calendar/{currency}"


def fetch_calendar(currency="USD", start_date=None, end_date=None, timeout=20):
today = date.today()
start_date = start_date or today.isoformat()
end_date = end_date or (today + timedelta(days=14)).isoformat()
query = urlencode({"start_date": start_date, "end_date": end_date})

with urlopen("{}?{}".format(BASE_URL.format(currency=currency), query), timeout=timeout) as response:
payload = json.load(response)

return payload.get("data", [])


def top_tier_blackout_dates(events):
dates = set()
for event in events:
if event.get("top_tier_for_currency") or event.get("market_tier") == 1:
event_time = event.get("announcement_datetime_utc") or event.get("announcement_datetime_local")
dates.add((event_time or event.get("date", ""))[:10])
return sorted(item for item in dates if item)


if __name__ == "__main__":
events = fetch_calendar(start_date="2026-07-01", end_date="2026-07-20")
print(top_tier_blackout_dates(events))