Exemplo n.º 1
0
    def batchCancelOrder(self, vtOrderIDList):
        """批量撤单"""
        # 查询报单对象

        reqList = []
        for vtOrderID in vtOrderIDList:
            order = self.mainEngine.getOrder(vtOrderID)

            # 如果查询成功
            if order:
                # 检查是否报单还有效,只有有效时才发出撤单指令
                orderFinished = (order.status == STATUS_ALLTRADED
                                 or order.status == STATUS_CANCELLED
                                 or order.status == STATUS_REJECTED
                                 or order.status == STATUS_CANCELLING
                                 or order.status == STATUS_CANCELINPROGRESS)

                if not orderFinished:
                    req = VtCancelOrderReq()
                    req.vtSymbol = order.vtSymbol
                    req.symbol = order.symbol
                    req.exchange = order.exchange
                    req.frontID = order.frontID
                    req.sessionID = order.sessionID
                    req.orderID = order.orderID

                    reqList.append(req)

        self.mainEngine.batchCancelOrder(reqList, order.gatewayName)
        self.writeCtaLog('策略%s: 对本地订单%s,发送批量撤单委托,实际发送单量%s' %
                         (order.byStrategy, vtOrderIDList, len(reqList)))
Exemplo n.º 2
0
    def cancelOrder(self, vtOrderID):
        """撤单"""
        # 查询报单对象
        order = self.mainEngine.getOrder(vtOrderID)

        # 如果查询成功
        if order:
            # 检查是否报单还有效,只有有效时才发出撤单指令
            orderFinished = (order.status == constant.STATUS_ALLTRADED
                             or order.status == constant.STATUS_CANCELLED
                             or order.status == constant.STATUS_REJECTED
                             or order.status == constant.STATUS_CANCELLING)

            if not orderFinished:
                req = VtCancelOrderReq()
                req.vtSymbol = order.vtSymbol
                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)
                self.writeCtaLog('策略%s: 对本地订单%s,品种%s发送撤单委托' %
                                 (order.byStrategy, vtOrderID, order.vtSymbol))
Exemplo n.º 3
0
    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.vtSymbol = order.vtSymbol
                req.symbol = order.symbol

                if order.contractType:  # 如果该品种是OKEX期货
                    req.contractType = order.contractType
                req.exchange = order.exchange
                req.frontID = order.frontID
                req.sessionID = order.sessionID
                req.orderID = order.orderID
                self.mainEngine.cancelOrder(req, order.gatewayName)
                self.writeCtaLog('策略:%s 对订单%s,品种%s发送撤单委托' %
                                 (order.bystrategy, vtOrderID, order.vtSymbol))