fix: 止盈止损委托校验现价并在平仓后撤余单

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-24 14:35:20 +08:00
parent 397e9cd9d8
commit fe1b651900
4 changed files with 174 additions and 19 deletions
+21
View File
@@ -831,6 +831,21 @@ class CtpBridge:
raise RuntimeError("CTP 拒单或未返回委托号(请检查合约代码、价格是否为最小变动价位整数倍)")
return str(vt_orderid)
def cancel_order(self, vt_orderid: str) -> bool:
if not self._engine or not vt_orderid:
return False
try:
order = self._engine.get_order(vt_orderid)
if order is None:
return False
req = order.create_cancel_request()
self._engine.cancel_order(req, GATEWAY_NAME)
logger.info("CTP 撤单 %s", vt_orderid)
return True
except Exception as exc:
logger.warning("CTP 撤单失败 %s: %s", vt_orderid, exc)
return False
def get_bridge() -> CtpBridge:
global _bridge
@@ -904,6 +919,12 @@ def ctp_list_active_orders(mode: str) -> list[dict[str, Any]]:
return b.list_active_orders()
def ctp_cancel_order(mode: str, vt_orderid: str) -> bool:
b = get_bridge()
b.ensure_connected(mode)
return b.cancel_order(vt_orderid)
def ctp_get_tick_price(mode: str, ths_code: str) -> Optional[float]:
"""CTP 柜台最新价(需已连接并订阅)。"""
b = get_bridge()