From e6aacbb327a54ba87979e7786c3f88cd7325656f Mon Sep 17 00:00:00 2001 From: vic-en Date: Sat, 6 Mar 2021 12:24:46 +0100 Subject: [PATCH] (fix) remove buggy check for multiple filled orders --- .../exchange/binance/binance_exchange.pyx | 74 ++++++++----------- .../binance/binance_in_flight_order.pyx | 3 +- 2 files changed, 31 insertions(+), 46 deletions(-) diff --git a/hummingbot/connector/exchange/binance/binance_exchange.pyx b/hummingbot/connector/exchange/binance/binance_exchange.pyx index 830aaafa10..ec048f8475 100755 --- a/hummingbot/connector/exchange/binance/binance_exchange.pyx +++ b/hummingbot/connector/exchange/binance/binance_exchange.pyx @@ -531,43 +531,34 @@ cdef class BinanceExchange(ExchangeBase): if tracked_order.is_done: if not tracked_order.is_failure: - exchange_trade_id = next(iter(tracked_order.trade_id_set)) - exchange_order_id = tracked_order.exchange_order_id - if self.is_confirmed_new_order_filled_event(str(exchange_trade_id), - str(exchange_order_id), - tracked_order.trading_pair): - if tracked_order.trade_type is TradeType.BUY: - self.logger().info(f"The market buy order {tracked_order.client_order_id} has completed " - f"according to order status API.") - self.c_trigger_event(self.MARKET_BUY_ORDER_COMPLETED_EVENT_TAG, - BuyOrderCompletedEvent(self._current_timestamp, - client_order_id, - tracked_order.base_asset, - tracked_order.quote_asset, - (tracked_order.fee_asset - or tracked_order.base_asset), - executed_amount_base, - executed_amount_quote, - tracked_order.fee_paid, - order_type)) - else: - self.logger().info(f"The market sell order {client_order_id} has completed " - f"according to order status API.") - self.c_trigger_event(self.MARKET_SELL_ORDER_COMPLETED_EVENT_TAG, - SellOrderCompletedEvent(self._current_timestamp, - client_order_id, - tracked_order.base_asset, - tracked_order.quote_asset, - (tracked_order.fee_asset - or tracked_order.quote_asset), - executed_amount_base, - executed_amount_quote, - tracked_order.fee_paid, - order_type)) + if tracked_order.trade_type is TradeType.BUY: + self.logger().info(f"The market buy order {tracked_order.client_order_id} has completed " + f"according to order status API.") + self.c_trigger_event(self.MARKET_BUY_ORDER_COMPLETED_EVENT_TAG, + BuyOrderCompletedEvent(self._current_timestamp, + client_order_id, + tracked_order.base_asset, + tracked_order.quote_asset, + (tracked_order.fee_asset + or tracked_order.base_asset), + executed_amount_base, + executed_amount_quote, + tracked_order.fee_paid, + order_type)) else: - self.logger().info( - f"The market order {tracked_order.client_order_id} was already filled, or order was not submitted by hummingbot." - f"Ignoring trade filled event in update_order_status.") + self.logger().info(f"The market sell order {client_order_id} has completed " + f"according to order status API.") + self.c_trigger_event(self.MARKET_SELL_ORDER_COMPLETED_EVENT_TAG, + SellOrderCompletedEvent(self._current_timestamp, + client_order_id, + tracked_order.base_asset, + tracked_order.quote_asset, + (tracked_order.fee_asset + or tracked_order.quote_asset), + executed_amount_base, + executed_amount_quote, + tracked_order.fee_paid, + order_type)) else: # check if its a cancelled order # if its a cancelled order, issue cancel and stop tracking order @@ -646,20 +637,13 @@ cdef class BinanceExchange(ExchangeBase): self.logger().debug(f"Event: {event_message}") continue - tracked_order.update_with_execution_report(event_message) + unique_update = tracked_order.update_with_execution_report(event_message) if execution_type == "TRADE": order_filled_event = OrderFilledEvent.order_filled_event_from_binance_execution_report(event_message) order_filled_event = order_filled_event._replace(trading_pair=convert_from_exchange_trading_pair(order_filled_event.trading_pair)) - exchange_trade_id = next(iter(tracked_order.trade_id_set)) - if self.is_confirmed_new_order_filled_event(str(exchange_trade_id), str(tracked_order.exchange_order_id), tracked_order.trading_pair): + if unique_update: self.c_trigger_event(self.MARKET_ORDER_FILLED_EVENT_TAG, order_filled_event) - else: - self.logger().info( - f"The market order {tracked_order.client_order_id} was already filled or order was not submitted by hummingbot." - f"Ignoring trade filled event of exchange trade id {str(exchange_trade_id)} in user stream.") - self.c_stop_tracking_order(tracked_order.client_order_id) - continue if tracked_order.is_done: if not tracked_order.is_failure: diff --git a/hummingbot/connector/exchange/binance/binance_in_flight_order.pyx b/hummingbot/connector/exchange/binance/binance_in_flight_order.pyx index e8a6044dae..085438160d 100644 --- a/hummingbot/connector/exchange/binance/binance_in_flight_order.pyx +++ b/hummingbot/connector/exchange/binance/binance_in_flight_order.pyx @@ -70,7 +70,7 @@ cdef class BinanceInFlightOrder(InFlightOrderBase): trade_id = execution_report["t"] if trade_id in self.trade_id_set: # trade already recorded - return + return False self.trade_id_set.add(trade_id) last_executed_quantity = Decimal(execution_report["l"]) last_commission_amount = Decimal(execution_report["n"]) @@ -84,6 +84,7 @@ cdef class BinanceInFlightOrder(InFlightOrderBase): self.fee_asset = last_commission_asset self.fee_paid += last_commission_amount self.last_state = last_order_state + return True def update_with_trade_update(self, trade_update: Dict[str, Any]): trade_id = trade_update["id"]