Fix stop-loss close loop spamming WeChat and blocking manual close.
Throttle close retries, skip monitor revive while pending, and dedupe notifications when CTP already has a close order. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -58,11 +58,14 @@ from modules.trading.order_pending import (
|
||||
from modules.core.db_conn import commit_retry, execute_retry
|
||||
from modules.trading.sl_tp_guard import (
|
||||
cancel_monitor_exit_orders,
|
||||
close_pending_active,
|
||||
ensure_monitor_order_columns,
|
||||
mark_close_pending,
|
||||
monitor_order_status,
|
||||
monitor_source_label,
|
||||
place_monitor_exit_orders,
|
||||
reconcile_monitors_without_position,
|
||||
should_skip_monitor_revive,
|
||||
start_sl_tp_guard_worker,
|
||||
write_manual_close_trade_log,
|
||||
)
|
||||
@@ -1195,6 +1198,8 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se
|
||||
|
||||
def _revive_closed_monitor(conn, symbol: str, direction: str) -> Optional[dict]:
|
||||
"""柜台仍有持仓但本地监控被误关时,恢复最近一条同品种记录。"""
|
||||
if should_skip_monitor_revive(symbol, direction):
|
||||
return None
|
||||
direction = (direction or "long").strip().lower()
|
||||
for r in conn.execute(
|
||||
"SELECT * FROM trade_order_monitors WHERE status='closed' ORDER BY id DESC LIMIT 40"
|
||||
@@ -3215,6 +3220,14 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se
|
||||
if not sym or price <= 0:
|
||||
conn.close()
|
||||
return jsonify({"ok": False, "error": "品种或价格无效"}), 400
|
||||
if close_pending_active(sym, direction):
|
||||
conn.close()
|
||||
return jsonify({"ok": False, "error": "平仓处理中,请稍候查看柜台委托"}), 400
|
||||
from modules.trading.sl_tp_guard import _has_pending_close_order
|
||||
if _has_pending_close_order(mode, sym, direction):
|
||||
mark_close_pending(sym, direction)
|
||||
conn.close()
|
||||
return jsonify({"ok": False, "error": "已有平仓委托在柜台排队,请勿重复提交"}), 400
|
||||
offset = "close_long" if direction == "long" else "close_short"
|
||||
capital = _capital(conn)
|
||||
mon = None
|
||||
@@ -3253,6 +3266,7 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se
|
||||
lots=lots, price=price, settings=_settings_dict(),
|
||||
order_type="market",
|
||||
)
|
||||
mark_close_pending(sym, direction)
|
||||
# 始终写本地记录:CTP 同步依赖内存开平配对,重启后或成交回报延迟时会漏记
|
||||
write_manual_close_trade_log(
|
||||
conn,
|
||||
|
||||
Reference in New Issue
Block a user