fix: custom tickers now placed in their natural asset-class tab

- Detect yfinance quote_type (CURRENCY→forex, FUTURE→energy, INDEX→indices,
  ETF→etfs, EQUITY→equities) when adding a custom ticker and persist it in
  market_watchlist.asset_class
- get_all_quotes() merges custom tickers into their proper group (e.g. EURUSD=X
  appears under Forex) instead of always under a separate "Custom" group
- "Custom" tab only shows tickers whose type couldn't be detected
- Add market_watchlist.asset_class migration; ensure backtest_lab_runs and
  market_watchlist are always created at init_db() time

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
OpenSquared
2026-06-22 22:11:31 +02:00
parent c3ea0b7f8c
commit 33097e1812
3 changed files with 36 additions and 18 deletions

View File

@@ -137,20 +137,23 @@ def get_all_quotes() -> Dict[str, List[Dict[str, Any]]]:
quotes.append(q)
result[asset_class] = quotes
# User-added custom tickers
# User-added custom tickers — placed in their detected asset class group
try:
from services.database import get_market_custom_tickers
custom_entries = get_market_custom_tickers()
if custom_entries:
custom_quotes = []
for entry in custom_entries:
q = get_quote(entry["ticker"])
if q:
q["name"] = entry["name"] or entry["ticker"]
q["asset_class"] = "custom"
custom_quotes.append(q)
if custom_quotes:
result["custom"] = custom_quotes
for entry in (custom_entries or []):
q = get_quote(entry["ticker"])
if not q:
continue
q["name"] = entry["name"] or entry["ticker"]
grp = entry.get("asset_class") or "custom"
q["asset_class"] = grp
if grp not in result:
result[grp] = []
# avoid duplicates (ticker already in built-in group)
existing_symbols = {x["symbol"] for x in result[grp]}
if q["symbol"] not in existing_symbols:
result[grp].append(q)
except Exception:
pass