Exemple #1
0
    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 offset == EMPTY_STRING:
                offsetCond = True
            else:
                offsetCond = order.offset == offset

            if order.symbol == symbol 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)
Exemple #2
0
    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))
Exemple #3
0
    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)
Exemple #4
0
 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))
Exemple #5
0
 def cancelOrder(self, vtOrderID):
     order = self.mainEngine.getOrder(vtOrderID)
     if order:
         # check if order still valid, only if valid, cancel order command will be sent
         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)
Exemple #6
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)    
Exemple #7
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)