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:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user