fix: 开仓时间读CTP OpenDate,止盈止损持久化且重启不丢失

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-25 15:05:58 +08:00
parent 7daed9bd3a
commit 4d60b958ce
4 changed files with 130 additions and 38 deletions
+11 -1
View File
@@ -20,6 +20,7 @@ from vnpy_bridge import (
ctp_list_positions,
ctp_status,
execute_order,
get_bridge,
)
logger = logging.getLogger(__name__)
@@ -478,7 +479,7 @@ def reconcile_monitors_without_position(conn, mode: str, *, grace_sec: int = 120
"""持仓已平时:关闭监控并撤销残留止盈止损挂单(新开仓 grace_sec 内不清理)。"""
if not ctp_status(mode).get("connected"):
return 0
positions = ctp_list_positions(mode)
positions = ctp_list_positions(mode, refresh_if_empty=False, refresh_margin=False)
position_keys: set[tuple[str, str]] = set()
for p in positions:
if int(p.get("lots") or 0) <= 0:
@@ -487,6 +488,15 @@ def reconcile_monitors_without_position(conn, mode: str, *, grace_sec: int = 120
direction = p.get("direction") or "long"
position_keys.add((sym, direction))
if not position_keys:
try:
acc = get_bridge().get_account()
margin_used = float(acc.get("balance") or 0) - float(acc.get("available") or 0)
if margin_used > 500:
return 0
except Exception:
return 0
now_ts = time.time()
def _monitor_within_grace(mon: dict) -> bool: