feat: saxo history
This commit is contained in:
BIN
backend/data/geooptions.db-journal
Normal file
BIN
backend/data/geooptions.db-journal
Normal file
Binary file not shown.
@@ -5,7 +5,7 @@ from pydantic import BaseModel
|
||||
|
||||
from services import saxo_auth
|
||||
from services.saxo_scheduler import get_watchlist, set_watchlist
|
||||
from services.database import get_saxo_snapshots
|
||||
from services.database import get_saxo_snapshots, get_saxo_snapshot_symbols
|
||||
|
||||
router = APIRouter(prefix="/api/saxo", tags=["saxo"])
|
||||
|
||||
@@ -36,6 +36,35 @@ def update_watchlist(req: WatchlistRequest):
|
||||
return {"symbols": get_watchlist()}
|
||||
|
||||
|
||||
def _validate_symbol(symbol: str) -> dict:
|
||||
from services.saxo_client import resolve_option_root_uic, SaxoNotConnected
|
||||
try:
|
||||
uic = resolve_option_root_uic(symbol)
|
||||
return {"symbol": symbol.upper(), "valid": True, "uic": uic, "error": None}
|
||||
except SaxoNotConnected as e:
|
||||
return {"symbol": symbol.upper(), "valid": False, "uic": None, "error": str(e)}
|
||||
except Exception as e:
|
||||
return {"symbol": symbol.upper(), "valid": False, "uic": None, "error": str(e)}
|
||||
|
||||
|
||||
@router.get("/validate")
|
||||
def validate_watchlist():
|
||||
"""Checks each watchlist symbol actually resolves to a real Saxo option-root instrument."""
|
||||
return [_validate_symbol(s) for s in get_watchlist()]
|
||||
|
||||
|
||||
@router.get("/validate/{symbol}")
|
||||
def validate_symbol(symbol: str):
|
||||
return _validate_symbol(symbol)
|
||||
|
||||
|
||||
@router.get("/symbols")
|
||||
def symbols_with_history():
|
||||
"""Distinct symbols that already have recorded snapshot history (may differ from the
|
||||
current watchlist — includes ad-hoc 'snapshot now' calls and previously-tracked symbols)."""
|
||||
return get_saxo_snapshot_symbols()
|
||||
|
||||
|
||||
@router.post("/snapshot-now/{symbol}")
|
||||
def snapshot_now(symbol: str):
|
||||
from services.saxo_client import snapshot_options_chain, SaxoNotConnected
|
||||
|
||||
@@ -6116,3 +6116,13 @@ def get_saxo_snapshots(symbol: Optional[str] = None, date_from: Optional[str] =
|
||||
rows = conn.execute(query, params).fetchall()
|
||||
conn.close()
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
|
||||
def get_saxo_snapshot_symbols() -> List[Dict[str, Any]]:
|
||||
conn = get_conn()
|
||||
rows = conn.execute("""
|
||||
SELECT symbol, COUNT(*) AS rows_count, MIN(snapshot_date) AS first_date, MAX(snapshot_date) AS last_date
|
||||
FROM saxo_option_snapshots GROUP BY symbol ORDER BY symbol
|
||||
""").fetchall()
|
||||
conn.close()
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
Reference in New Issue
Block a user