From 73df767ac0eefb3e8a5ca38a28feca5863d64e88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=A5=E5=BE=AE?= Date: Fri, 10 Jul 2026 10:26:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B9=B0=E5=85=A5=E5=8C=BA=E7=94=A8live?= =?UTF-8?q?=5Fprices+=E7=BB=9F=E4=B8=80DB=E8=AF=BB=E5=8F=96+=E6=8A=A5?= =?UTF-8?q?=E5=91=8A=E5=89=8D=E9=AA=8C=E4=BB=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/generate_report.py | 13 ++++++++++--- scripts/strategy_lifecycle.py | 9 +++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/scripts/generate_report.py b/scripts/generate_report.py index 74ae17b9..0ee6b445 100644 --- a/scripts/generate_report.py +++ b/scripts/generate_report.py @@ -99,11 +99,18 @@ def main(): import sqlite3 _conn = sqlite3.connect(str(SCRIPTS_DIR.parent / "data" / "mofin.db")) _actionable = _conn.execute( - "SELECT code FROM holding_strategies WHERE status='active' " - "AND timing_signal IN ('买入','可买入','可加仓','卖出','止盈')" + "SELECT hs.code, lp.price, hs.entry_low, hs.entry_high FROM holding_strategies hs " + "LEFT JOIN live_prices lp ON hs.code = lp.code " + "WHERE hs.status='active' " + "AND hs.timing_signal IN ('买入','可买入','可加仓','卖出','止盈')" ).fetchall() _conn.close() - for (_code,) in _actionable: + for _code, _price, _el, _eh in _actionable: + # 价格必须在买入区内或附近(不高于上沿20%),否则不触发重评 + if _price and _el and _eh and _price > 0 and _el > 0 and _eh > 0: + if _price > _eh * 1.20: + print(f" ⏭️ {_code}: 价{_price}超买入区上沿+{((_price/_eh)-1)*100:.0f}%,跳过重评") + continue try: subprocess.run( ["python3", str(SCRIPTS_DIR / "per_stock_reassess.py"), _code], diff --git a/scripts/strategy_lifecycle.py b/scripts/strategy_lifecycle.py index dfc0a108..c5891e55 100644 --- a/scripts/strategy_lifecycle.py +++ b/scripts/strategy_lifecycle.py @@ -741,14 +741,19 @@ def batch_fetch_prices(codes): # 主通道:从 DB 读取(price_monitor 唯一价格入口) try: import sqlite3 - db = sqlite3.connect('/home/hmo/web-dashboard/data/mofin.db') + db = sqlite3.connect('/home/hmo/MoFin/data/mofin.db') db.row_factory = sqlite3.Row for raw_code in codes: raw_code = str(raw_code).split('_')[0] if not raw_code: continue + # 优先级:live_prices > holdings > holding_strategies row = db.execute( - "SELECT price, change_pct FROM holdings WHERE code=? AND is_active=1", (raw_code,) + "SELECT price, change_pct FROM live_prices WHERE code=?", (raw_code,) ).fetchone() + if not row: + row = db.execute( + "SELECT price, change_pct FROM holdings WHERE code=? AND is_active=1", (raw_code,) + ).fetchone() if not row: row = db.execute( "SELECT price, change_pct FROM holding_strategies WHERE code=? AND status='active' ORDER BY updated_at DESC LIMIT 1", (raw_code,)