From 88885eae76ffd617a4454ac52e2afcd594199557 Mon Sep 17 00:00:00 2001 From: xxm Date: Wed, 19 Aug 2026 16:36:19 +0800 Subject: [PATCH] =?UTF-8?q?fix(P2-A+D):=20=E5=BF=AB=E7=85=A7=E7=98=A6?= =?UTF-8?q?=E8=BA=AB=E2=80=94=E2=80=94write=5Fholding=5Fstrategy=E5=85=88?= =?UTF-8?q?=E5=AF=B9=E6=AF=94=E6=96=B0=E6=97=A7=E5=86=85=E5=AE=B9,?= =?UTF-8?q?=E6=97=A0=E5=8F=98=E5=8C=96=E4=B8=8D=E5=BF=AB=E7=85=A7(66%?= =?UTF-8?q?=E5=9E=83=E5=9C=BE=E5=BF=AB=E7=85=A7=E6=B6=88=E9=99=A4)?= =?UTF-8?q?=E3=80=82=E5=AF=B9=E6=AF=94=E5=85=B3=E9=94=AE=E5=AD=97=E6=AE=B5?= =?UTF-8?q?:entry/stop/tp/signal/rr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/profile-scripts/mofin_db.py | 33 ++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/deploy/profile-scripts/mofin_db.py b/deploy/profile-scripts/mofin_db.py index 7e417e70..ca45480f 100644 --- a/deploy/profile-scripts/mofin_db.py +++ b/deploy/profile-scripts/mofin_db.py @@ -1998,11 +1998,36 @@ def snapshot_strategy_history(conn, code: str, source_trigger: str = "write_hold def write_holding_strategy(conn, code: str, name: str, data: dict, source_trigger: str = "write_holding_strategy") -> tuple[bool, str]: - """写入持仓策略(替代 decisions.json 单条写入)。data 必须包含 currency。""" + """写入持仓策略(替代 decisions.json 单条写入)。data 必须包含 currency。 + + 2026-08-19 老莫 A+D 修复(快照瘦身): + - 覆写前对比新旧内容,有变化才快照(减少 66% 垃圾快照) + - 对比关键字段:entry_low/entry_high/stop_loss/take_profit/timing_signal/rr_ratio + - 无变化 → 跳过快照;有变化 → snapshot_strategy_history + """ try: - # ── 覆写前快照旧行 ── - snapshot_strategy_history(conn, code, source_trigger) - + # ── 变化检测:对比新旧关键字段,有变化才快照 ── + _old_row = conn.execute( + "SELECT entry_low, entry_high, stop_loss, take_profit, timing_signal, rr_ratio " + "FROM holding_strategies WHERE code=? AND status='active'", + (code,) + ).fetchone() + _should_snapshot = False + if _old_row: + # 对比关键字段是否变化 + _fields = ['entry_low', 'entry_high', 'stop_loss', 'take_profit', 'timing_signal', 'rr_ratio'] + for i, f in enumerate(_fields): + old_v = _old_row[i] or 0 + new_v = data.get(f, old_v) # 没传则用旧值(不算变化) + if str(old_v) != str(new_v): + _should_snapshot = True + break + else: + _should_snapshot = True # 无旧值(新建)→ 快照 + if _should_snapshot: + snapshot_strategy_history(conn, code, source_trigger) + else: + print(f" [SNAPSHOT] {code} 参数无变化,跳过快照", flush=True) currency = data.get('currency', 'CNY') # Serialize JSON fields