From f621e5466c64bc099583ef81d569ce5c2018386c Mon Sep 17 00:00:00 2001 From: xxm Date: Mon, 24 Aug 2026 10:29:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=87=8D=E8=AF=84=E9=93=BE=E8=B7=AF?= =?UTF-8?q?=E5=85=A8=E4=BF=AE=E2=80=94=E2=80=94=E2=91=A0strategy=5Flifecyc?= =?UTF-8?q?le=20942=E8=A1=8Cdetect=5Fscenario=E6=AE=8B=E7=95=99(8/20?= =?UTF-8?q?=E5=9B=9B=E6=80=81=E5=BA=9F=E5=BC=83=E6=BC=8F=E6=94=B9,?= =?UTF-8?q?=E6=89=80=E6=9C=8912=E7=BB=B4=E9=87=8D=E8=AF=84NameError?= =?UTF-8?q?=E5=85=A8=E5=B4=A9)=E2=91=A1=5Fdo=5Fllm=5Freassess=E5=AD=90?= =?UTF-8?q?=E8=BF=9B=E7=A8=8Brc=E6=A0=A1=E9=AA=8C+reassessed=5Fat=E6=96=B0?= =?UTF-8?q?=E9=B2=9C=E5=BA=A6=E6=A0=A1=E9=AA=8C(=E9=98=B2=E6=97=A7?= =?UTF-8?q?=E7=AD=96=E7=95=A5=E5=86=92=E5=85=85=E9=87=8D=E8=AF=84=E7=BB=93?= =?UTF-8?q?=E8=AE=BA)=E2=91=A2952=E8=A1=8Cresult=20None=E5=88=A4=E7=A9=BA(?= =?UTF-8?q?=E6=AF=8F2=E5=88=86=E9=92=9FNoneType=E5=88=B7=E5=B1=8F)?= =?UTF-8?q?=E2=91=A3=E9=87=8D=E8=AF=84=E6=9C=AA=E7=94=9F=E6=95=88=E5=8F=91?= =?UTF-8?q?=E5=8E=9F=E5=A7=8B=E5=91=8A=E8=AD=A6+=E4=BA=BA=E5=B7=A5?= =?UTF-8?q?=E6=A0=B8=E6=9F=A5=E6=A0=87=E6=B3=A8(02202=E9=AC=BC=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=A0=B9=E6=B2=BB)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/profile-scripts/price_monitor.py | 27 +++++++++++++++++--- deploy/profile-scripts/strategy_lifecycle.py | 20 +++++++-------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/deploy/profile-scripts/price_monitor.py b/deploy/profile-scripts/price_monitor.py index 36a0f241..21b2a94d 100644 --- a/deploy/profile-scripts/price_monitor.py +++ b/deploy/profile-scripts/price_monitor.py @@ -131,6 +131,10 @@ try: capture_output=True, text=True, timeout=180 ) _mark_reassess(code) + # 2026-08-24 防鬼消息:子进程失败不得继续读旧策略冒充"重评结论" + if _r.returncode != 0: + print(f" ⚠️ {code} 12维重评子进程失败(rc={_r.returncode}): {(_r.stderr or _r.stdout or '')[-300:]}", file=sys.stderr, flush=True) + return None except Exception as e: print(f" ⚠️ {code} 12维重评异常: {e}", file=sys.stderr) return None @@ -140,9 +144,17 @@ try: _c = _sq.connect("/home/hmo/MoFin/data/mofin.db", timeout=30) _c.row_factory = _sq.Row _row = _c.execute( - "SELECT timing_signal, action, stop_loss, take_profit, entry_low, entry_high, rr_ratio " + "SELECT timing_signal, action, stop_loss, take_profit, entry_low, entry_high, rr_ratio, reassessed_at " "FROM holding_strategies WHERE code=? AND status='active'", (code,)).fetchone() _c.close() + # 2026-08-24 防鬼消息:rc=0但LLM失败时策略未刷新(reassessed_at不变), + # 旧策略不得冒充"重评结论"——reassessed_at 超过10分钟视为重评未生效 + if _row: + from datetime import datetime as _dt + _ra = _row["reassessed_at"] + if not _ra or (_dt.now() - _dt.fromisoformat(str(_ra))).total_seconds() > 600: + print(f" ⚠️ {code} 重评后策略未刷新(reassessed_at={_ra}),按重评失败处理", file=sys.stderr, flush=True) + return None if _row: return { "timing_signal": _row["timing_signal"] or "", @@ -764,6 +776,12 @@ def run_once(round_label=""): else: _zone_entries.append(f"{name}({code}) {price}→入区+重评{timing_signal}|RR={rr}") outputs.append(f" 📨 止损重评→{timing_signal}: {str(action)[:120]}") + else: + # 2026-08-24:重评未生效(冷却/子进程失败)→发原始告警+人工核查标注, + # 绝不拿旧策略冒充"重评结论"(02202卖出/深套持有鬼消息教训) + if _can_push(code, "stop_loss"): + _push_action("止损告警", f"⚠️ {name}({code}) {price} → 跌破止损{hi}!(12维重评未生效,暂无最新结论,请人工核查)") + outputs.append(f" ⚠️ {code} 重评未生效,已发原始止损告警") except Exception as e: outputs.append(f" ⚠️ 止损重评失败: {e}") try: @@ -949,8 +967,11 @@ def run_once(round_label=""): # 调用技术面驱动重评(非机械百分比) result = _do_llm_reassess(code, name, price, cost, shares, d.get("action", "")) - outputs.append(f" 📊 新策略: 损{result['stop_loss']} 盈{result['take_profit']} 区{result['entry_low']}~{result['entry_high']} RR={result['rr_ratio']}") - reassesed_codes.append(code) + if result: + outputs.append(f" 📊 新策略: 损{result['stop_loss']} 盈{result['take_profit']} 区{result['entry_low']}~{result['entry_high']} RR={result['rr_ratio']}") + reassesed_codes.append(code) + else: + outputs.append(f" ⏭ {code} 重评未生效(冷却/子进程失败),沿用现有策略") except Exception as e: outputs.append(f" ⚠️ 重评失败: {e}") diff --git a/deploy/profile-scripts/strategy_lifecycle.py b/deploy/profile-scripts/strategy_lifecycle.py index af0d0d07..7a63297f 100644 --- a/deploy/profile-scripts/strategy_lifecycle.py +++ b/deploy/profile-scripts/strategy_lifecycle.py @@ -939,18 +939,18 @@ def reassess_strategy(code, name, price, cost, shares, current_action, # ----- 筹码分布支撑/阻力(中长线参考,加情景权重) ----- chip_sr = None chip_weight = 0.5 # 默认中等权重 - regime = detect_scenario() - regime_id = regime.get("id", "weak_consolidation") - - # 情景决定筹码因子权重 - if regime_id == "weak_consolidation": + # 2026-08-24 修复:detect_scenario(四态已废弃,8/20漏改此处)→ load_market_regime(三态) + # 映射:choppy≈weak_consolidation trend_up≈bullish_recovery trend_down≈sharp_decline + _mr_row = load_market_regime() + regime_id = (_mr_row or {}).get("regime", "choppy") + + # 温区决定筹码因子权重 + if regime_id == "choppy": chip_weight = 0.9 # 震荡市筹码最准 - elif regime_id == "bullish_recovery": + elif regime_id == "trend_up": chip_weight = 0.4 # 上涨趋势筹码阻力可能被突破 - elif regime_id == "sharp_decline": - chip_weight = 0.2 # 急跌中筹码支撑可能失效 - elif regime_id == "sector_rotation": - chip_weight = 0.6 # 轮动市中筹码有一定参考 + elif regime_id == "trend_down": + chip_weight = 0.2 # 下跌中筹码支撑可能失效 try: chip_sr = calc_chip_sr(code, price)