feat: option lab

This commit is contained in:
OpenSquared
2026-07-21 17:23:55 +02:00
parent b6e9b96dc4
commit 78eda311f8
7 changed files with 275 additions and 82 deletions

View File

@@ -183,6 +183,10 @@ def init_db():
sort_order INTEGER DEFAULT 0,
added_at TEXT DEFAULT (datetime('now'))
)""",
# Optional link to a Saxo watchlist symbol (services.saxo_scheduler) — lets Options
# Lab's Saxo section show only broker data for instruments the user actually tracks
# here, instead of an independently-managed Saxo symbol list.
"ALTER TABLE instruments_watchlist ADD COLUMN saxo_symbol TEXT",
# Wavelets — saved optimization/simulation runs (ported from InstrumentSimulator's
# WaveletOptimizationRun: form/results are free-form JSON blobs, not modeled relationally)
"""CREATE TABLE IF NOT EXISTS wavelet_simulations (
@@ -3270,13 +3274,40 @@ def remove_market_custom_ticker(ticker: str) -> bool:
def get_instruments_watchlist() -> List[Dict]:
conn = get_conn()
rows = conn.execute(
"SELECT ticker, name, asset_class, sort_order, added_at "
"SELECT ticker, name, asset_class, sort_order, added_at, saxo_symbol "
"FROM instruments_watchlist ORDER BY sort_order ASC, added_at ASC"
).fetchall()
conn.close()
return [dict(r) for r in rows]
def set_instrument_watchlist_saxo_symbol(ticker: str, saxo_symbol: Optional[str]) -> bool:
"""Link (or unlink, if saxo_symbol is None/empty) a tracked instrument to a Saxo
watchlist symbol. Linking also adds that symbol to services.saxo_scheduler's own
watchlist if it isn't there yet, so it actually starts getting snapshotted. Unlinking
does NOT remove it from the Saxo watchlist — it may still be wanted directly, or by
another linked instrument; remove it from Config -> Saxo if it's truly no longer needed."""
from services.saxo_scheduler import get_watchlist, set_watchlist
ticker = ticker.upper()
saxo_symbol = (saxo_symbol or "").strip().upper() or None
conn = get_conn()
row = conn.execute("SELECT ticker FROM instruments_watchlist WHERE ticker = ?", (ticker,)).fetchone()
if row is None:
conn.close()
return False
conn.execute("UPDATE instruments_watchlist SET saxo_symbol = ? WHERE ticker = ?", (saxo_symbol, ticker))
conn.commit()
conn.close()
if saxo_symbol:
current = get_watchlist()
if saxo_symbol not in current:
set_watchlist(current + [saxo_symbol])
return True
def add_instrument_watchlist(ticker: str, name: str = "", asset_class: str = "unknown") -> bool:
conn = get_conn()
try: