vn.py量化社区
By Traders, For Traders.
Member
avatar
加入于:
帖子: 13
声望: 0

我想知道cancelOrder是否有返回,所以查了ctaTemplate.py,里面的method是这样的:
def cancelOrder(self, vtOrderID):
"""撤单"""

    # 如果发单号为空字符串,则不进行后续操作
    if not vtOrderID:
        return

    if STOPORDERPREFIX in vtOrderID:
        self.ctaEngine.cancelStopOrder(vtOrderID)
    else:
        self.ctaEngine.cancelOrder(vtOrderID)

我接着看回ctaEngine.py,
def cancelOrder(self, vtOrderID):
"""撤单"""

    # 查询报单对象
    order = self.mainEngine.getOrder(vtOrderID)

    # 如果查询成功
    if order:
        # 检查是否报单还有效,只有有效时才发出撤单指令
        orderFinished = (order.status==STATUS_ALLTRADED or order.status==STATUS_CANCELLED)
        if not orderFinished:
            req = VtCancelOrderReq()
            req.symbol = order.symbol
            req.exchange = order.exchange
            req.frontID = order.frontID
            req.sessionID = order.sessionID
            req.orderID = order.orderID
            self.mainEngine.cancelOrder(req, order.gatewayName)    

ctaEngine检查是否有这个单,检查这个单是否全部成交或者cancelle,如果都没有,就通过mainEngine去cancel。

在mainEngine里,则是通过gateway直接cancel了
def cancelOrder(self, cancelOrderReq, gatewayName):
"""对特定接口撤单"""
gateway = self.getGateway(gatewayName)

    if gateway:
        gateway.cancelOrder(cancelOrderReq)   

我交易期货,所以看回ctp
def cancelOrder(self, cancelOrderReq):
"""撤单"""
self.tdApi.cancelOrder(cancelOrderReq)

也是没有返回值。

请问有哪位知道cancelOrder会返回什么值吗?这样我好判断是撤单成功还是不成功?
谢谢!

Administrator
avatar
加入于:
帖子: 2125
声望: 96

没有返回值,需要通过onOrder收到的OrderData回报来判断

Member
avatar
加入于:
帖子: 13
声望: 0

好的,谢谢!

© 2015-2019 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3