feat: srategy builder

This commit is contained in:
OpenSquared
2026-07-18 23:25:13 +02:00
parent 8fe18a8ff9
commit ca30e37942
3 changed files with 81 additions and 154 deletions

View File

@@ -6138,6 +6138,27 @@ def get_saxo_snapshot_symbols() -> List[Dict[str, Any]]:
return [dict(r) for r in rows]
def get_latest_saxo_snapshot_rows(symbol: str) -> List[Dict[str, Any]]:
"""One row per (expiry_date, strike, option_type) — the freshest of the accumulated
5-min snapshots for that contract, not the whole history. Powers the Strategy Builder,
which reads exclusively from this accumulated history (no live yfinance/Saxo call)."""
conn = get_conn()
rows = conn.execute("""
SELECT s.* FROM saxo_option_snapshots s
JOIN (
SELECT expiry_date, strike, option_type, MAX(created_at) AS max_created
FROM saxo_option_snapshots WHERE symbol = ?
GROUP BY expiry_date, strike, option_type
) latest
ON s.expiry_date = latest.expiry_date AND s.strike = latest.strike
AND s.option_type = latest.option_type AND s.created_at = latest.max_created
WHERE s.symbol = ?
ORDER BY s.expiry_date, s.strike
""", (symbol, symbol)).fetchall()
conn.close()
return [dict(r) for r in rows]
def upsert_saxo_catalog_rows(rows: List[Dict[str, Any]]):
if not rows:
return