예제 #1
0
    def cancelOrder(self, vtOrderID):
        """撤单"""
        # 查询报单对象
        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.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))
예제 #2
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)))
예제 #3
0
파일: ctaEngine.py 프로젝트: wycwywfwa/vnpy
    def cancelOrders(self, symbol, offset=EMPTY_STRING):
        """撤销所有单"""
        # Symbol参数:指定合约的撤单;
        # OFFSET参数:指定Offset的撤单,缺省不填写时,为所有

        l = self.mainEngine.getAllWorkingOrders()

        self.writeCtaLog(u'从所有订单{0}中撤销{1}'.format(len(l), symbol))

        for order in l:

            if symbol == EMPTY_STRING:
                symbolCond = True
            else:
                symbolCond = order.symbol == symbol

            if offset == EMPTY_STRING:
                offsetCond = True
            else:
                offsetCond = order.offset == offset

            if symbolCond and offsetCond:
                req = VtCancelOrderReq()
                req.symbol = order.symbol
                req.exchange = order.exchange
                req.frontID = order.frontID
                req.sessionID = order.sessionID
                req.orderID = order.orderID
                self.writeCtaLog(u'撤单:{0}/{1},{2}{3}手'.format(
                    order.symbol, order.orderID, order.offset,
                    order.totalVolume - order.tradedVolume))
                self.mainEngine.cancelOrder(req, order.gatewayName)
예제 #4
0
파일: ctaEngine.py 프로젝트: wycwywfwa/vnpy
    def cancelOrder(self, vtOrderID):
        """撤单"""
        # 查询报单对象
        # 1.调用主引擎接口,查询委托单对象
        order = self.mainEngine.getOrder(vtOrderID)

        # 如果查询成功
        if order:
            # 2.检查是否报单(委托单)还有效,只有有效时才发出撤单指令
            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)
            else:
                if order.status == STATUS_ALLTRADED:
                    self.writeCtaLog(u'委托单({0}已执行,无法撤销'.format(vtOrderID))
                if order.status == STATUS_CANCELLED:
                    self.writeCtaLog(u'委托单({0}已撤销,无法再次撤销'.format(vtOrderID))
        # 查询不成功
        else:
            self.writeCtaLog(u'委托单({0}不存在'.format(vtOrderID))
예제 #5
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.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)    
예제 #6
0
파일: ctaEngine.py 프로젝트: porfavor/vnpy
 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)    
예제 #7
0
파일: ctaEngine.py 프로젝트: QuantFeng/vnpy
    def cancelOrder(self, vtOrderID):
        """撤单"""
        print "%s.%s.%s" % (__name__, self.__class__.__name__, get_current_function_name())  # 查询报单对象
        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)