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:
@@ -143,9 +143,41 @@ def test_list_strategy_snapshots_hides_duplicate_keys():
|
||||
assert int(stop_rows[0]["id"]) == 12
|
||||
|
||||
|
||||
def test_dedupe_keeps_manual_over_stop_loss():
|
||||
conn = _mem_conn()
|
||||
payload = json.dumps({"symbol": "ONDO/USDT"}, ensure_ascii=False)
|
||||
for snap_id, label in ((10, "止损"), (11, "手动平仓")):
|
||||
conn.execute(
|
||||
"""INSERT INTO strategy_trade_snapshots (
|
||||
id, strategy_type, source_id, symbol, result_label, snapshot_json, closed_at, created_at, pnl_amount
|
||||
) VALUES (?,?,?,?,?,?,?,?,?)""",
|
||||
(
|
||||
snap_id,
|
||||
STRATEGY_TREND,
|
||||
7,
|
||||
"ONDO/USDT",
|
||||
label,
|
||||
payload,
|
||||
"2026-06-08 08:44:00",
|
||||
"2026-06-08 08:44:00",
|
||||
-2.23,
|
||||
),
|
||||
)
|
||||
conn.commit()
|
||||
removed = dedupe_strategy_snapshots(conn)
|
||||
conn.commit()
|
||||
assert removed == 1
|
||||
row = conn.execute(
|
||||
"SELECT result_label FROM strategy_trade_snapshots WHERE source_id=?",
|
||||
(7,),
|
||||
).fetchone()
|
||||
assert row["result_label"] == "手动平仓"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_save_trend_plan_snapshot_skips_duplicate_result()
|
||||
test_dedupe_strategy_snapshots_handles_many_duplicates()
|
||||
test_dedupe_strategy_snapshots_keeps_latest_id()
|
||||
test_list_strategy_snapshots_hides_duplicate_keys()
|
||||
test_dedupe_keeps_manual_over_stop_loss()
|
||||
print("all ok")
|
||||
|
||||
Reference in New Issue
Block a user