feat: option lab
This commit is contained in:
@@ -26,14 +26,16 @@ def list_watchlist():
|
||||
@router.get("/quotes")
|
||||
def watchlist_quotes():
|
||||
from services.database import get_instruments_watchlist
|
||||
from services.data_fetcher import get_quote
|
||||
from services.data_fetcher import get_quote_with_volatility
|
||||
items = []
|
||||
for row in get_instruments_watchlist():
|
||||
q = get_quote(row["ticker"]) or {}
|
||||
q = get_quote_with_volatility(row["ticker"]) or {}
|
||||
items.append({
|
||||
**row,
|
||||
"price": q.get("price"),
|
||||
"change_pct": q.get("change_pct"),
|
||||
"volatility_pct": q.get("volatility_pct"),
|
||||
"volatility_change_pct": q.get("volatility_change_pct"),
|
||||
})
|
||||
return {"items": items}
|
||||
|
||||
@@ -78,3 +80,19 @@ def reorder(body: ReorderBody):
|
||||
from services.database import reorder_instruments_watchlist
|
||||
reorder_instruments_watchlist(body.tickers)
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
class SaxoLinkBody(BaseModel):
|
||||
saxo_symbol: str | None = None
|
||||
|
||||
|
||||
@router.put("/{ticker}/saxo-link")
|
||||
def set_saxo_link(ticker: str, body: SaxoLinkBody):
|
||||
"""Link this tracked instrument to a Saxo watchlist symbol (or pass null to unlink)
|
||||
so Options Lab's Saxo section shows broker data for it. Adds the symbol to
|
||||
services.saxo_scheduler's watchlist automatically if it wasn't already there."""
|
||||
from services.database import set_instrument_watchlist_saxo_symbol
|
||||
ok = set_instrument_watchlist_saxo_symbol(ticker, body.saxo_symbol)
|
||||
if not ok:
|
||||
raise HTTPException(404, f"'{ticker}' is not in the instruments watchlist")
|
||||
return {"ticker": ticker.strip().upper(), "saxo_symbol": (body.saxo_symbol or "").strip().upper() or None}
|
||||
|
||||
Reference in New Issue
Block a user