feat: srategy builder
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user