feat(scripts): add backfill for missing trend strategy snapshots

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-07 16:53:50 +08:00
parent f976697203
commit 9257a8051f
3 changed files with 274 additions and 3 deletions
+4 -3
View File
@@ -127,6 +127,7 @@ def save_trend_plan_snapshot(
result_label: str,
exit_price: float | None = None,
pnl_amount: float | None = None,
closed_at: str | None = None,
) -> None:
init_strategy_snapshot_table(conn)
row = _row_dict(plan_row)
@@ -134,7 +135,7 @@ def save_trend_plan_snapshot(
if plan_id <= 0:
return
m = cfg.get("app_module")
closed_at = (
close_ts = (closed_at or "").strip() or (
m.app_now_str()
if m is not None and hasattr(m, "app_now_str")
else datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S")
@@ -158,10 +159,10 @@ def save_trend_plan_snapshot(
result_label,
row.get("status"),
row.get("opened_at"),
closed_at,
close_ts,
pnl_amount,
_json_dumps(payload),
closed_at,
close_ts,
),
)
prune_strategy_snapshots(conn, keep=STRATEGY_SNAPSHOTS_MAX_ROWS)