feat: dynamic market ticker watchlist (Markets page)
Add ability to add/remove custom tickers (e.g. EURCHF=X) on the Markets & Prices page without editing config. Tickers are validated via yfinance, persisted in market_watchlist SQLite table, merged into the quotes feed as a 'custom' group, and shown in a dedicated tab with per-card remove buttons. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -39,6 +39,38 @@ def watchlist():
|
||||
return WATCHLIST
|
||||
|
||||
|
||||
@router.get("/custom-tickers")
|
||||
def list_custom_tickers():
|
||||
from services.database import get_market_custom_tickers
|
||||
return get_market_custom_tickers()
|
||||
|
||||
|
||||
@router.post("/custom-tickers/{ticker}")
|
||||
def add_custom_ticker(ticker: str):
|
||||
from services.data_fetcher import get_quote
|
||||
from services.database import add_market_custom_ticker
|
||||
import yfinance as yf
|
||||
ticker = ticker.strip().upper()
|
||||
q = get_quote(ticker)
|
||||
if not q or not q.get("price"):
|
||||
from fastapi import HTTPException
|
||||
raise HTTPException(400, f"Ticker '{ticker}' not found on yfinance")
|
||||
try:
|
||||
info = yf.Ticker(ticker).fast_info
|
||||
name = getattr(info, "long_name", None) or getattr(info, "short_name", None) or ticker
|
||||
except Exception:
|
||||
name = ticker
|
||||
add_market_custom_ticker(ticker, name)
|
||||
return {"ticker": ticker, "name": name, "price": q["price"]}
|
||||
|
||||
|
||||
@router.delete("/custom-tickers/{ticker}")
|
||||
def remove_custom_ticker(ticker: str):
|
||||
from services.database import remove_market_custom_ticker
|
||||
remove_market_custom_ticker(ticker.strip().upper())
|
||||
return {"removed": ticker.upper()}
|
||||
|
||||
|
||||
@router.get("/validate")
|
||||
def validate_ticker(symbol: str = Query(..., description="Ticker to validate against yfinance")):
|
||||
"""Check if a ticker is fetchable. Returns valid=True + live price/name, or valid=False + reason."""
|
||||
|
||||
Reference in New Issue
Block a user