fix: 止盈止损委托校验现价并在平仓后撤余单
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+3
-12
@@ -27,6 +27,7 @@ from sl_tp_guard import (
|
||||
ensure_monitor_order_columns,
|
||||
monitor_order_status,
|
||||
place_monitor_exit_orders,
|
||||
reconcile_monitors_without_position,
|
||||
start_sl_tp_guard_worker,
|
||||
sync_all_sl_tp_orders,
|
||||
)
|
||||
@@ -158,18 +159,8 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se
|
||||
return False
|
||||
|
||||
def _sync_trade_monitors_with_ctp(conn, mode: str) -> int:
|
||||
"""关闭无对应 CTP 持仓的 active 监控(委托被拒或未成交的幽灵记录)。"""
|
||||
if not ctp_status(mode).get("connected"):
|
||||
return 0
|
||||
position_keys = _ctp_position_keys(mode)
|
||||
closed = 0
|
||||
for r in conn.execute("SELECT * FROM trade_order_monitors WHERE status='active'").fetchall():
|
||||
mon = dict(r)
|
||||
if _monitor_matches_ctp_position(mon, position_keys):
|
||||
continue
|
||||
conn.execute("UPDATE trade_order_monitors SET status='closed' WHERE id=?", (mon["id"],))
|
||||
closed += 1
|
||||
return closed
|
||||
"""关闭无对应 CTP 持仓的监控,并撤销残留止盈止损挂单。"""
|
||||
return reconcile_monitors_without_position(conn, mode)
|
||||
|
||||
def _effective_active_position_count(conn, mode: str) -> int:
|
||||
if ctp_status(mode).get("connected"):
|
||||
|
||||
Reference in New Issue
Block a user