hummingbot: Binance perpetual: Stuck cancelling an order

Describe the bug Opening ticket for tracking: When running a perpetual market making strategy using binance perpetual for long period (days), there are instances that the bot gets stuck in a repeated loop, attempting to cancel an order. When you check the exchange, there are no active closing position. In this screenshot, both orders x-3QreWesy-SDEUT75601643346706004336 and x-3QreWesy-BDEUT75601643346706004126 fails to cancel. In the logs, these affected orders didn’t receive any completion event for the cancellation. binance_perp-stuck-cancelling

Steps To Reproduce Here are the steps to reproduce the issue (see attachments in the section below):

  1. Create a perpetual market making strategy using binance_perpetual as connector
  2. Start the the strategy and leave the bot running for long period or few days.
  3. Regularly monitor the bot for any cancellation issue

Screenshots

Release version 0.46.0

Attachments

binance-perp-cancel-issue.zip

WARNING: Do NOT publish any exchange API keys or your wallet’s private key. Whoever has access to them may steal your assets!

Optional: your discord username:

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 37 (18 by maintainers)

Most upvoted comments

@raymondcarl @amitds1997 I found the error, the issue is in the connector. I will provide a solution for today

@raymondcarl nice! Yes probably there is a bug in the order tracker of the strategy, I will check it now. It’s strange because it’s only happening in perpetuals and with Binance but well. All of you are using perpetuals market making?

@cardosofede this impacts all strategy that uses binance_perpetual not just perpetual market making strategy. This is happening with other strategy such as hedge too. It should be an issue related to binance_perpetual connector only.

I am also trying to debug this issue on my end.

My observations:

  1. The order is present in self._sb_order_tracker.in_flight_cancels but not present in self._market_info.market.in_flight_orders (shown by @cardosofede in the comment above).
  2. The active_orders property depends upon market_pair_to_active_orders and the logic for that is different b/w PerpetualMarketMakingOrderTracker and the base OrderTracker
# In PerpetualMarketMakingOrderTracker
    @property
    def market_pair_to_active_orders(self) -> Dict[MarketTradingPairTuple, List[LimitOrder]]:
        market_pair_to_orders = {}
        for market_pair, orders_map in self.tracked_limit_orders_map.items():
            market_pair_to_orders[market_pair] = list(self.tracked_limit_orders_map[market_pair].values())
        return market_pair_to_orders

# In OrderTracker
    @property
    def market_pair_to_active_orders(self) -> Dict[MarketTradingPairTuple, List[LimitOrder]]:
        market_pair_to_orders = {}
        market_pairs = self._tracked_limit_orders.keys()
        for market_pair in market_pairs:
            limit_orders = []
            for limit_order in self._tracked_limit_orders[market_pair].values():
                if self.c_has_in_flight_cancel(limit_order.client_order_id):
                    continue
                limit_orders.append(limit_order)
            market_pair_to_orders[market_pair] = limit_orders
        return market_pair_to_orders

If PerpetualMarketMakingOrderTracker.market_pair_to_active_orders had the same logic, I can see how we would not face this issue because the order is still in in_flight_cancels. But this kind of leaves the actual question still open about why the state was not correctly updated after the order cancellation and it is still present in in_flight_cancels

I think that I found something! In Flight Orders from the connector:

Image

Active orders from the OrderTracker:

Image

Tomorrow I will continue with the research ! Hope that I can solve this soon.

@raymondcarl hey Raymond! thanks for the previous investigation, tomorrow I will fix this issue (hope so haha). Some things about your comments.

  • The ws is not necessary here because the cancel is via rest
  • If we are missing one of the messages (i.e. canceled order message) the client should have some logic to handle this via rest.
  • The method fetch order is using the dictionaries stored in the client order tracker: in_flight_orders + cached_orders
  • The execute cancel has a logic to stop tracking the order if the response is that the order don’t exist image

My guess is that as we are using the cached orders + inflight orders to cancel the order, it will try to cancel the same order at least for 30 seconds (the default value for the TTL cache).

Tomorrow I will debug it because this are all thoughts!

Is this one already assigned to you? @cardosofede