Update liquidation price after partial exits

This commit is contained in:
Matthias 2022-07-25 19:50:55 +02:00
parent 44fba79531
commit 6da51a0455
2 changed files with 7 additions and 4 deletions

View File

@ -1703,6 +1703,12 @@ class FreqtradeBot(LoggingMixin):
# If a entry order was closed, force update on stoploss on exchange # If a entry order was closed, force update on stoploss on exchange
if order.get('side') == trade.entry_side: if order.get('side') == trade.entry_side:
trade = self.cancel_stoploss_on_exchange(trade) 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. # TODO: Margin will need to use interest_rate as well.
# interest_rate = self.exchange.get_interest_rate() # interest_rate = self.exchange.get_interest_rate()
trade.set_isolated_liq(self.exchange.get_liquidation_price( trade.set_isolated_liq(self.exchange.get_liquidation_price(
@ -1712,10 +1718,6 @@ class FreqtradeBot(LoggingMixin):
open_rate=trade.open_rate, open_rate=trade.open_rate,
is_short=trade.is_short 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 # Updating wallets when order is closed
self.wallets.update() self.wallets.update()

View File

@ -2033,6 +2033,7 @@ def test_update_trade_state_exception(mocker, default_conf_usdt, is_short, limit
trade = MagicMock() trade = MagicMock()
trade.open_order_id = '123' trade.open_order_id = '123'
trade.amount = 123
# Test raise of OperationalException exception # Test raise of OperationalException exception
mocker.patch( mocker.patch(