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:
@@ -97,6 +97,7 @@ def init_db():
|
||||
name TEXT,
|
||||
added_at TEXT DEFAULT (datetime('now'))
|
||||
)""",
|
||||
"ALTER TABLE market_watchlist ADD COLUMN asset_class TEXT DEFAULT 'custom'",
|
||||
]:
|
||||
try:
|
||||
c.execute(_sql)
|
||||
@@ -2318,18 +2319,18 @@ def remove_watchlist_ticker(ticker: str) -> bool:
|
||||
def get_market_custom_tickers() -> List[Dict]:
|
||||
conn = get_conn()
|
||||
rows = conn.execute(
|
||||
"SELECT ticker, name, added_at FROM market_watchlist ORDER BY added_at ASC"
|
||||
"SELECT ticker, name, asset_class, added_at FROM market_watchlist ORDER BY added_at ASC"
|
||||
).fetchall()
|
||||
conn.close()
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
|
||||
def add_market_custom_ticker(ticker: str, name: str = "") -> bool:
|
||||
def add_market_custom_ticker(ticker: str, name: str = "", asset_class: str = "custom") -> bool:
|
||||
conn = get_conn()
|
||||
try:
|
||||
conn.execute(
|
||||
"INSERT OR IGNORE INTO market_watchlist (ticker, name) VALUES (?, ?)",
|
||||
(ticker.upper(), name),
|
||||
"INSERT OR IGNORE INTO market_watchlist (ticker, name, asset_class) VALUES (?, ?, ?)",
|
||||
(ticker.upper(), name, asset_class),
|
||||
)
|
||||
inserted = conn.total_changes > 0
|
||||
conn.commit()
|
||||
|
||||
Reference in New Issue
Block a user