fix(P2-A+D): 快照瘦身——write_holding_strategy先对比新旧内容,无变化不快照(66%垃圾快照消除)。对比关键字段:entry/stop/tp/signal/rr
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user