feat: instrument model

This commit is contained in:
OpenSquared
2026-07-03 21:48:55 +02:00
parent 716d8fa56c
commit 3be72e44cc
4 changed files with 178 additions and 6 deletions

View File

@@ -809,3 +809,30 @@ def get_all_overrides(instrument: str) -> List[Dict[str, Any]]:
return [dict(r) for r in rows]
finally:
conn.close()
class CalendarBackfillBody(BaseModel):
from_date: str # ISO date string "YYYY-MM-DD"
to_date: Optional[str] = None # defaults to today
@router.post("/ff-calendar/backfill")
def backfill_calendar(body: CalendarBackfillBody) -> Dict[str, Any]:
"""
Backfill ff_calendar with historical data from ForexFactory HTML scraper.
Scrapes week by week from from_date to to_date (or today).
Skips weeks already populated. Runs synchronously — may take several minutes for long ranges.
"""
from datetime import date as date_type
from services.ff_calendar import sync_historical_range
try:
from_d = date_type.fromisoformat(body.from_date[:10])
to_d = date_type.fromisoformat(body.to_date[:10]) if body.to_date else date_type.today()
except ValueError as e:
raise HTTPException(status_code=400, detail=f"Invalid date: {e}")
if (to_d - from_d).days > 730:
raise HTTPException(status_code=400, detail="Range too large (max 2 years)")
result = sync_historical_range(from_d, to_d)
return result