Skip to content

Commit

Permalink
(fix) remove buggy check for multiple filled orders
Browse files Browse the repository at this point in the history
  • Loading branch information
vic-en committed Mar 6, 2021
1 parent 1055c6d commit e6aacbb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 46 deletions.
74 changes: 29 additions & 45 deletions hummingbot/connector/exchange/binance/binance_exchange.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand All @@ -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"]
Expand Down

0 comments on commit e6aacbb

Please sign in to comment.