def cancel(self, id: Text, origin: [BarData, TickData, TradeData, OrderData, PositionData] = None, **kwargs): if "." in id: orderid = id.split(".")[1] if origin is None: exchange = kwargs.get("exchange") if isinstance(exchange, Exchange): exchange = exchange.value local_symbol = kwargs.get("local_symbol") elif origin: exchange = origin.exchange.value local_symbol = origin.local_symbol if origin is None and len(kwargs) == 0: """ 如果两个都不传""" order = self.app.recorder.get_order(id) if not order: print("找不到订单啦... 撤不了哦") return None exchange = order.exchange.value local_symbol = order.local_symbol req = helper.generate_cancel_req_by_str(order_id=orderid, exchange=exchange, symbol=local_symbol) return self.looper.cancel_order(req)
def cancel(self, id: Text, origin: [BarData, TickData, TradeData, OrderData, PositionData] = None, **kwargs): """ 撤单, 在不涉传递origin的情况下请使用local_symbol和exchange字段传递值 Args: id (Text): 单号 origin(Any(BarData, TradeData, TickData, OrderData, PositionData)): 快速获取品种和交易所信息 exchange(Exchange): 交易所代码 local_symbol(str): 合约代码 Returns: str: 单号 Example: self.cancel("id1", tick) # or self.cancel("id2", None, exchange=Exchange.SHFE, local_symbol="rb2101.SHFE") """ if "." in id: orderid = id.split(".")[1] else: orderid = id if origin is None: exchange = kwargs.get("exchange") if isinstance(exchange, Exchange): exchange = exchange.value local_symbol = kwargs.get("local_symbol") elif origin: try: exchange = origin.exchange.value except AttributeError: exchange = origin.exchange local_symbol = origin.local_symbol if origin is None and len(kwargs) == 0: """ 如果两个都不传""" order = self.app.recorder.get_order(id) if not order: print("找不到订单啦... 撤不了哦") return None try: exchange = order.exchange.value except AttributeError: exchange = order.exchange local_symbol = order.local_symbol req = helper.generate_cancel_req_by_str(order_id=orderid, exchange=exchange, symbol=local_symbol) return self.cancel_order(req)