From cf9b87ef4d5d8aa0a08babae7f99b556fe2d2437 Mon Sep 17 00:00:00 2001 From: xxm Date: Thu, 20 Aug 2026 05:33:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20price=5Fmonitor=E4=B8=89=E5=A4=84?= =?UTF-8?q?=E8=BF=9B=E5=8C=BA=E8=A7=A6=E5=8F=91=E6=94=B9=E4=B8=BA=E7=9C=9F?= =?UTF-8?q?12=E7=BB=B4LLM=E9=87=8D=E8=AF=84(=5Fdo=5Fllm=5Freassess?= =?UTF-8?q?=E8=B0=83per=5Fstock=5Freassess)+30min=E5=86=B7=E5=8D=B4(?= =?UTF-8?q?=E8=A1=A5=E4=B8=8A=E6=AC=A1=E8=A2=AB=E5=9B=9E=E6=BB=9A=E7=9A=84?= =?UTF-8?q?commit,=E6=A0=B9=E6=B2=BB=E6=8A=80=E6=9C=AF=E5=BF=AB=E7=AE=97)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/profile-scripts/price_monitor.py | 77 ++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 7 deletions(-) diff --git a/deploy/profile-scripts/price_monitor.py b/deploy/profile-scripts/price_monitor.py index 921edd7f..0379069e 100644 --- a/deploy/profile-scripts/price_monitor.py +++ b/deploy/profile-scripts/price_monitor.py @@ -81,6 +81,73 @@ from market_config import kline_symbol, market_for_code sys.path.insert(0, "/home/hmo/web-dashboard") try: from strategy_lifecycle import reassess_strategy, reassess_with_context + import subprocess as _sp2 + _REASSESS_SCRIPT = "/home/hmo/MoFin/deploy/profile-scripts/per_stock_reassess.py" + _REASSESS_OLD = "/home/hmo/MoFin/data/.price_reassess_last.json" + + def _done_reassess_recently(code): + """冷却检查:同票 30 分钟内已触发过 12维重评 → 跳过(防每2分钟重复烧LLM)""" + try: + import os as _os + if _os.path.exists(_REASSESS_OLD): + _last = json.load(open(_REASSESS_OLD, encoding="utf-8")) + if code in _last and time.time() - _last[code] < 1800: + return True + except Exception: + pass + return False + + def _mark_reassess(code): + """记录重评时间(冷却标记)""" + try: + import os as _os + _last = {} + if _os.path.exists(_REASSESS_OLD): + try: + _last = json.load(open(_REASSESS_OLD, encoding="utf-8")) + except Exception: + _last = {} + _last[code] = time.time() + json.dump(_last, open(_REASSESS_OLD, "w"), ensure_ascii=False) + except Exception: + pass + + def _do_llm_reassess(code, name, price, cost, shares, current_action): + """真正12维LLM重评(per_stock_reassess.py)。返回最新参数的dict或None。""" + if _done_reassess_recently(code): + print(f" ⏭ {code} 30分钟内已重评,跳过(冷却)", flush=True) + return None + try: + _r = _sp2.run( + [sys.executable, _REASSESS_SCRIPT, code], + capture_output=True, text=True, timeout=180 + ) + _mark_reassess(code) + except Exception as e: + print(f" ⚠️ {code} 12维重评异常: {e}", file=sys.stderr) + return None + # 重评后从DB读最新参数(子进程已写库) + try: + import sqlite3 as _sq + _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 " + "FROM holding_strategies WHERE code=? AND status='active'", (code,)).fetchone() + _c.close() + if _row: + return { + "timing_signal": _row["timing_signal"] or "", + "action": _row["action"] or "", + "stop_loss": _row["stop_loss"] or 0, + "take_profit": _row["take_profit"] or 0, + "entry_low": _row["entry_low"] or 0, + "entry_high": _row["entry_high"] or 0, + "rr_ratio": _row["rr_ratio"] or 0, + } + except Exception as e: + print(f" ⚠️ {code} 读重评结果失败: {e}", file=sys.stderr) + return None HAS_REASSESS = True except ImportError: HAS_REASSESS = False @@ -607,7 +674,7 @@ def run_once(round_label=""): cost = d.get("cost", 0) or 0 shares = d.get("shares", 0) or 0 current_action = d.get("action", "") - result = reassess_with_context(code, name, price, cost, shares, current_action) + result = _do_llm_reassess(code, name, price, cost, shares, current_action) if result: timing_signal = result.get("timing_signal", "") action = result.get("action", "") @@ -679,7 +746,7 @@ def run_once(round_label=""): cost = d.get("cost", 0) or 0 shares = d.get("shares", 0) or 0 current_action = d.get("action", "") - result = reassess_with_context(code, name, price, cost, shares, current_action) + result = _do_llm_reassess(code, name, price, cost, shares, current_action) if result: timing_signal = result.get("timing_signal", "") action = result.get("action", "") @@ -834,11 +901,7 @@ def run_once(round_label=""): sentiment = "bullish" # 调用技术面驱动重评(非机械百分比) - result = reassess_strategy( - code, name, price, cost, shares, - current_action=d.get("action", ""), - volume_signal="中性", sentiment=sentiment, - ) + 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) except Exception as e: