From 6da51a04552a6cc32feb321008d7707211de1732 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 25 Jul 2022 19:50:55 +0200 Subject: [PATCH] Update liquidation price after partial exits --- freqtrade/freqtradebot.py | 10 ++++++---- tests/test_freqtradebot.py | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index bfba1380d..e3fc78941 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -1703,6 +1703,12 @@ class FreqtradeBot(LoggingMixin): # If a entry order was closed, force update on stoploss on exchange if order.get('side') == trade.entry_side: trade = self.cancel_stoploss_on_exchange(trade) + if not self.edge: + # TODO: should shorting/leverage be supported by Edge, + # then this will need to be fixed. + trade.adjust_stop_loss(trade.open_rate, self.strategy.stoploss, initial=True) + if order.get('side') == trade.entry_side or trade.amount > 0: + # Must also run for partial exits # TODO: Margin will need to use interest_rate as well. # interest_rate = self.exchange.get_interest_rate() trade.set_isolated_liq(self.exchange.get_liquidation_price( @@ -1712,10 +1718,6 @@ class FreqtradeBot(LoggingMixin): open_rate=trade.open_rate, is_short=trade.is_short )) - if not self.edge: - # TODO: should shorting/leverage be supported by Edge, - # then this will need to be fixed. - trade.adjust_stop_loss(trade.open_rate, self.strategy.stoploss, initial=True) # Updating wallets when order is closed self.wallets.update() diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index 6d297b621..a03127577 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -2033,6 +2033,7 @@ def test_update_trade_state_exception(mocker, default_conf_usdt, is_short, limit trade = MagicMock() trade.open_order_id = '123' + trade.amount = 123 # Test raise of OperationalException exception mocker.patch(