From 17f037cec62c838d37c877377babc2574d4e9a0f Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 27 Dec 2021 16:07:43 +0100 Subject: [PATCH] Extract order_fee handling from update_trade_state --- freqtrade/freqtradebot.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 4e9cf9ab9..5d0773437 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -1359,7 +1359,7 @@ class FreqtradeBot(LoggingMixin): return False # Update trade with order values - logger.info('Found open order for %s', trade) + logger.info(f'Found open order for {trade}') try: order = action_order or self.exchange.fetch_order_or_stoploss_order(order_id, trade.pair, @@ -1376,15 +1376,7 @@ class FreqtradeBot(LoggingMixin): # Handling of this will happen in check_handle_timedout. return True - # Try update amount (binance-fix) - try: - new_amount = self.get_real_amount(trade, order) - if not isclose(safe_value_fallback(order, 'filled', 'amount'), new_amount, - abs_tol=constants.MATH_CLOSE_PREC): - order['amount'] = new_amount - order.pop('filled', None) - except DependencyException as exception: - logger.warning("Could not update trade amount: %s", exception) + order = self.handle_order_fee(trade, order) trade.update(order) trade.recalc_trade_from_orders() @@ -1439,6 +1431,18 @@ class FreqtradeBot(LoggingMixin): return real_amount return amount + def handle_order_fee(self, trade: Trade, order: Dict[str, Any]) -> Dict[str, Any]: + # Try update amount (binance-fix) + try: + new_amount = self.get_real_amount(trade, order) + if not isclose(safe_value_fallback(order, 'filled', 'amount'), new_amount, + abs_tol=constants.MATH_CLOSE_PREC): + order['amount'] = new_amount + order.pop('filled', None) + except DependencyException as exception: + logger.warning("Could not update trade amount: %s", exception) + return order + def get_real_amount(self, trade: Trade, order: Dict) -> float: """ Detect and update trade fee.