From 504f51fabb6b199b48fbe11d54bfb0e90bdce5b8 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 27 Sep 2023 06:30:03 +0200 Subject: [PATCH] Fix liquidation price setting in backtesting closes #9205 --- freqtrade/optimize/backtesting.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index 9855fb595..ab0ce4e3f 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -598,6 +598,16 @@ class Backtesting: if order and self._get_order_filled(order.ft_price, row): order.close_bt_order(current_date, trade) if not (order.ft_order_side == trade.exit_side and order.safe_amount == trade.amount): + # trade is still open + trade.set_liquidation_price(self.exchange.get_liquidation_price( + pair=trade.pair, + open_rate=trade.open_rate, + is_short=trade.is_short, + amount=trade.amount, + stake_amount=trade.stake_amount, + leverage=trade.leverage, + wallet_balance=trade.stake_amount, + )) self._call_adjust_stop(current_date, trade, order.ft_price) # pass return True @@ -894,16 +904,6 @@ class Backtesting: trade.adjust_stop_loss(trade.open_rate, self.strategy.stoploss, initial=True) - trade.set_liquidation_price(self.exchange.get_liquidation_price( - pair=pair, - open_rate=propose_rate, - amount=amount, - stake_amount=trade.stake_amount, - leverage=trade.leverage, - wallet_balance=trade.stake_amount, - is_short=is_short, - )) - order = Order( id=self.order_id_counter, ft_trade_id=trade.id,