Fix hub full-close double-booking trend plans.

Sync active plans after hub position close, merge final close snapshots per plan, and backfill missing trade records when ending an already-stopped plan.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-08 09:06:36 +08:00
parent e71bfe095c
commit cfa28e7f4e
6 changed files with 344 additions and 7 deletions
+24
View File
@@ -6902,6 +6902,30 @@ def stop_trend_pullback(pid):
conn = get_db()
row = conn.execute("SELECT * FROM trend_pullback_plans WHERE id=? AND status='active'", (pid,)).fetchone()
if not row:
from strategy_trend_register import (
_ensure_trend_plan_trade_record,
_trend_plan_trade_exists,
build_trend_config,
)
cfg = app.extensions.get("strategy_trend_cfg") or build_trend_config(
sys.modules[__name__]
)
stopped = conn.execute(
"SELECT id FROM trend_pullback_plans WHERE id=? "
"AND status IN ('stopped_sl','stopped_tp','stopped_manual')",
(pid,),
).fetchone()
if stopped and not _trend_plan_trade_exists(conn, pid):
try:
if _ensure_trend_plan_trade_record(cfg, conn, pid, prefer_label="手动平仓"):
conn.close()
flash("计划已结束,已补录缺失的交易记录")
return redirect(url_for("strategy_trend_page"))
except Exception as e:
conn.close()
flash(f"补录交易记录失败:{e}")
return redirect(url_for("strategy_trend_page"))
conn.close()
flash("未找到运行中的趋势回调计划")
return redirect("/trade")