def on_orders_match(self, order: Order): """订单撮合""" hq = self.hq_client.get_realtime_data(order.pt_symbol) if hq is not None: now_price = float(hq.loc[0, "price"]) if order.price_type == PriceType.MARKET.value: order.order_price = now_price # 订单成交 self.on_orders_deal(order) return elif order.price_type == PriceType.LIMIT.value: if order.order_type == OrderType.BUY.value: if order.order_price >= now_price: if order.status == Status.SUBMITTING.value: order.trade_price = now_price # 订单成交 self.on_orders_deal(order) return else: if order.order_price <= now_price: if order.status == Status.SUBMITTING.value: order.trade_price = now_price # 订单成交 self.on_orders_deal(order) return # 没有成交更新订单状态 self.on_orders_status_modify(order)
def on_orders_match(self, order: Order): """订单撮合""" try: hq = self.hq_client.get_realtime_data(order.pt_symbol) if len(hq): ask1 = float(hq.loc[0, "ask1"]) bid1 = float(hq.loc[0, 'bid1']) if order.order_type == OrderType.BUY.value: # 涨停 if ask1 == 0: return # 市价委托即时成交 if order.price_type == PriceType.MARKET.value: order.order_price = ask1 order.trade_price = ask1 self.on_order_deal(order) return True # 限价委托 elif order.price_type == PriceType.LIMIT.value: if order.order_price >= ask1: order.trade_price = ask1 # 订单成交 self.on_order_deal(order) return True else: # 跌停 if bid1 == 0: return # 市价委托即时成交 if order.price_type == PriceType.MARKET.value: order.order_price = bid1 order.trade_price = bid1 self.on_order_deal(order) return True # 限价委托 elif order.price_type == PriceType.LIMIT.value: if order.order_price <= bid1: order.trade_price = bid1 # 订单成交 self.on_order_deal(order) return True except Exception as e: self.write_log(traceback.format_exc()) return False