diff --git a/scripts/mofin_collect.py b/scripts/mofin_collect.py index a35c65e9..efcdfddb 100644 --- a/scripts/mofin_collect.py +++ b/scripts/mofin_collect.py @@ -30,7 +30,7 @@ try: cur = conn.cursor() # 读所有活跃持仓及其最新策略更新时间 rows = cur.execute(""" - SELECT h.code, h.name, h.price, h.position_pct, + SELECT h.code, h.name, h.price, h.cost, h.shares, h.position_pct, hs.stop_loss, hs.take_profit, hs.entry_low, hs.entry_high, hs.created_at, hs.action FROM holdings h @@ -111,11 +111,39 @@ try: print(f" ❌ CREATE_STRATEGY {code} {name} 失败: {e}", flush=True) conn.commit() + + # === 自选股策略检查 + 强制重评 === + wl_fresh = 0 + wl_stale = 0 + wl_error = 0 + try: + for wr in conn.execute("SELECT code, name, price, entry_low, entry_high, stop_loss FROM watchlist_stocks WHERE is_active=1"): + code = wr["code"] + name = wr["name"] + # 自选股无cost/shares,传0 + try: + from strategy_lifecycle import reassess_with_context + result = reassess_with_context( + code, name, wr["price"] or 0, + 0, 0, "" + ) + if result and result.get("action"): + wl_stale += 1 + print(f" 📋 WATCHLIST_REASSESS {code} {name}: →{result['action'][:60]}", flush=True) + else: + wl_fresh += 1 + except Exception as e: + wl_error += 1 + print(f" ❌ WATCHLIST_REASSESS {code} {name} 失败: {e}", flush=True) + except Exception as e: + print(f" ⚠️ 自选股检查跳过: {e}", flush=True) + conn.close() total = len(rows) - print(f"策略检查完成: {total}只持仓, {fresh_count}新鲜, {stale_count}过期(已强制重评), {no_strategy_count}无策略(已创建)", flush=True) - if stale_count > 0 or no_strategy_count > 0: + wl_total = wl_fresh + wl_stale + wl_error + print(f"策略检查完成: {total}只持仓({fresh_count}新鲜/{stale_count}过期/{no_strategy_count}无策略) + {wl_total}只自选({wl_fresh}无需/{wl_stale}已重评/{wl_error}失败)", flush=True) + if stale_count > 0 or no_strategy_count > 0 or wl_stale > 0: print(f"⚠️ 重评完成: {stale_count + no_strategy_count}只已强制刷新, LLM可基于最新策略给出建议", flush=True) except Exception as e: print(f"WARN: strategy_freshness_check跳过 ({e})", flush=True)