feat: option

This commit is contained in:
OpenSquared
2026-07-18 22:04:43 +02:00
parent 6db2705466
commit b0b7f9bfda
9 changed files with 300 additions and 24 deletions

View File

@@ -4,7 +4,7 @@ from fastapi import APIRouter, HTTPException, Query
from pydantic import BaseModel
from services import saxo_auth
from services.saxo_scheduler import get_watchlist, set_watchlist
from services.saxo_scheduler import get_watchlist, set_watchlist, get_snapshot_minutes, set_snapshot_minutes, run_snapshot_pass
from services.database import (
get_saxo_snapshots, get_saxo_snapshot_symbols,
get_saxo_catalog, get_saxo_catalog_summary, upsert_saxo_catalog_rows,
@@ -72,6 +72,29 @@ def symbols_with_history():
return get_saxo_snapshot_symbols()
class SettingsRequest(BaseModel):
snapshot_minutes: float
@router.get("/settings")
def get_settings():
return {"snapshot_minutes": get_snapshot_minutes()}
@router.put("/settings")
def update_settings(req: SettingsRequest):
set_snapshot_minutes(req.snapshot_minutes)
return {"snapshot_minutes": get_snapshot_minutes()}
@router.post("/snapshot-now")
def snapshot_now_all():
"""Manual immediate refresh of the whole watchlist (doesn't wait for the periodic poll)."""
if not saxo_auth.get_status().get("connected"):
raise HTTPException(status_code=401, detail="Saxo n'est pas connecté")
return {"results": run_snapshot_pass()}
@router.post("/snapshot-now/{symbol}")
def snapshot_now(symbol: str):
from services.saxo_client import snapshot_options_chain, SaxoNotConnected, SaxoApiError

View File

@@ -30,6 +30,13 @@ def saxo_callback(code: str = Query(...), state: str = Query(...)):
except Exception as e:
logger.error(f"[Saxo OAuth] Token exchange failed: {e}")
return RedirectResponse(f"{FRONTEND_CONFIG_URL}?saxo_error=1")
# Snapshot the whole watchlist right away — don't make the user wait for the next
# scheduled poll after connecting. Runs in the background so the redirect isn't delayed.
import threading
from services.saxo_scheduler import run_snapshot_pass
threading.Thread(target=run_snapshot_pass, daemon=True, name="saxo-connect-snapshot").start()
return RedirectResponse(f"{FRONTEND_CONFIG_URL}?saxo_connected=1")