diff --git a/deploy/profile-scripts/watchlist_auto_exit.py b/deploy/profile-scripts/watchlist_auto_exit.py index b1bdeec6..88ea4468 100644 --- a/deploy/profile-scripts/watchlist_auto_exit.py +++ b/deploy/profile-scripts/watchlist_auto_exit.py @@ -86,6 +86,14 @@ def main(dry_run=False): "SELECT strategy_name FROM holding_strategies WHERE code=? AND status='active'", (code,)).fetchone() _strat_name = (_strat[0] if _strat and _strat[0] else "unknown") + # 2026-08-18 修复:holding.strategy_name 为 unknown 时,回退用 candidates 里旧的 sector + # (候选的 sector 是正确策略标签,但 holding 早期 promote 时 source_strategy 可能没继承) + if _strat_name == "unknown" or not _strat_name: + _old_sec = conn.execute( + "SELECT sector FROM candidates WHERE code=?", (code,)).fetchone() + _old_sec_v = str(_old_sec[0]).strip() if _old_sec and _old_sec[0] else "" + if _old_sec_v and _old_sec_v != "unknown": + _strat_name = _old_sec_v conn.execute( "INSERT INTO candidates (code, name, sector, reason, dropped, drop_reason, promoted, " "source_strategy, created_at) "