From 5e689327c781ba975beeb2dcbdce91b3bbdb4e4a Mon Sep 17 00:00:00 2001 From: hmo Date: Wed, 29 Jul 2026 09:50:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=AD=A2=E7=9B=88/=E6=AD=A2=E6=8D=9F?= =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=8C=89=E7=9C=9F=E5=AE=9E=E6=88=90=E6=9C=AC?= =?UTF-8?q?=E5=8C=BA=E5=88=86=E8=AF=AD=E4=B9=89=E2=80=94=E2=80=94=E6=B5=AE?= =?UTF-8?q?=E4=BA=8F=E4=B8=AD=E7=9A=84=E7=AD=96=E7=95=A5=E7=9B=AE=E6=A0=87?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E6=94=B9=E7=A7=B0=E5=8F=8D=E5=BC=B9=E5=87=8F?= =?UTF-8?q?=E4=BB=93=E4=BD=8D=E5=B9=B6=E6=98=BE=E7=A4=BA=E6=88=90=E6=9C=AC?= =?UTF-8?q?=EF=BC=8C=E9=98=B2=E6=AD=A2=E6=8A=8A-25%=E7=9A=84=E5=8F=8D?= =?UTF-8?q?=E5=BC=B9=E8=AF=AF=E8=AF=BB=E4=B8=BA=E6=AD=A2=E7=9B=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/profile-scripts/mofin_db.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/deploy/profile-scripts/mofin_db.py b/deploy/profile-scripts/mofin_db.py index 88fb8820..98318e1c 100644 --- a/deploy/profile-scripts/mofin_db.py +++ b/deploy/profile-scripts/mofin_db.py @@ -1635,14 +1635,24 @@ def check_strategy_outcomes(conn): mid = mid or price # fallback closed = False + # ── 持仓成本感知(2026-07-29 老爸抓包:策略版"止盈"可能远低于真实成本,必须区分语义)── + _hc = conn.execute("SELECT cost, shares FROM holdings WHERE code=? AND is_active=1 AND shares>0", (code,)).fetchone() + _cost = float(_hc[0]) if _hc and _hc[0] else 0.0 + _real_pnl = round((price - _cost) / _cost * 100, 1) if _cost > 0 else None if tp and tp > 0 and price >= tp: pnl_pct = round((tp - mid) / mid * 100, 1) if mid > 0 else 0 + _reason = '止盈触发' if (_real_pnl is None or _real_pnl > 0) else '反弹减仓触发' conn.execute(""" UPDATE strategy_tracking SET status='hit_tp', closed_at=datetime('now','localtime'), - close_price=?, close_reason='止盈触发', theoretical_pnl=? + close_price=?, close_reason=?, theoretical_pnl=? WHERE id=? - """, (price, pnl_pct, tid)) - print(f" [TRACK] {code} v{tid} 止盈! {price}≥{tp} +{pnl_pct}%", flush=True) + """, (price, _reason, pnl_pct, tid)) + if _real_pnl is not None and _real_pnl <= 0: + print(f" [TRACK] {code} v{tid} 反弹减仓位! {price}≥{tp},成本{_cost},浮亏{_real_pnl}%(减仓窗口,非止盈)", flush=True) + elif _real_pnl is not None: + print(f" [TRACK] {code} v{tid} 止盈! {price}≥{tp} 实际盈利+{_real_pnl}%(成本{_cost})", flush=True) + else: + print(f" [TRACK] {code} v{tid} 追踪版本止盈 {price}≥{tp} +{pnl_pct}%(未持仓)", flush=True) closed = True elif sl and sl > 0 and price <= sl: pnl_pct = round((sl - mid) / mid * 100, 1) if mid > 0 else -5 @@ -1651,7 +1661,10 @@ def check_strategy_outcomes(conn): close_price=?, close_reason='止损触发', theoretical_pnl=? WHERE id=? """, (price, pnl_pct, tid)) - print(f" [TRACK] {code} v{tid} 止损! {price}≤{sl} {pnl_pct}%", flush=True) + if _real_pnl is not None: + print(f" [TRACK] {code} v{tid} 止损! {price}≤{sl},成本{_cost},实际{_real_pnl}%", flush=True) + else: + print(f" [TRACK] {code} v{tid} 止损! {price}≤{sl} {pnl_pct}%", flush=True) closed = True if closed: