Simplify and align liquidation price handling

This commit is contained in:
Matthias
2022-03-06 16:27:55 +01:00
parent 612ede5e48
commit 6360ef029c
4 changed files with 28 additions and 31 deletions

View File

@@ -3897,7 +3897,7 @@ def test_trailing_stop_loss_positive(
freqtrade.enter_positions()
trade = Trade.query.first()
trade.is_short = is_short
assert trade.is_short == is_short
oobj = Order.parse_from_ccxt_object(limit_order[eside], limit_order[eside]['symbol'], eside)
trade.update_trade(oobj)
caplog.set_level(logging.DEBUG)

View File

@@ -117,28 +117,30 @@ def test_set_stop_loss_isolated_liq(fee):
)
trade.set_isolated_liq(0.09)
assert trade.isolated_liq == 0.09
assert trade.stop_loss == 0.09
assert trade.initial_stop_loss == 0.09
assert trade.stop_loss is None
assert trade.initial_stop_loss is None
trade._set_stop_loss(0.1, (1.0/9.0))
assert trade.isolated_liq == 0.09
assert trade.stop_loss == 0.1
assert trade.initial_stop_loss == 0.09
assert trade.initial_stop_loss == 0.1
trade.set_isolated_liq(0.08)
assert trade.isolated_liq == 0.08
assert trade.stop_loss == 0.1
assert trade.initial_stop_loss == 0.09
assert trade.initial_stop_loss == 0.1
trade.set_isolated_liq(0.11)
assert trade.isolated_liq == 0.11
assert trade.stop_loss == 0.11
assert trade.initial_stop_loss == 0.09
trade._set_stop_loss(0.1, 0)
assert trade.isolated_liq == 0.11
assert trade.stop_loss == 0.11
assert trade.initial_stop_loss == 0.09
assert trade.initial_stop_loss == 0.1
# lower stop doesn't move stoploss
trade._set_stop_loss(0.1, 0)
assert trade.isolated_liq == 0.11
assert trade.stop_loss == 0.11
assert trade.initial_stop_loss == 0.1
trade.stop_loss = None
trade.isolated_liq = None
@@ -156,28 +158,30 @@ def test_set_stop_loss_isolated_liq(fee):
trade.set_isolated_liq(0.09)
assert trade.isolated_liq == 0.09
assert trade.stop_loss == 0.09
assert trade.initial_stop_loss == 0.09
assert trade.stop_loss is None
assert trade.initial_stop_loss is None
trade._set_stop_loss(0.08, (1.0/9.0))
assert trade.isolated_liq == 0.09
assert trade.stop_loss == 0.08
assert trade.initial_stop_loss == 0.09
assert trade.initial_stop_loss == 0.08
trade.set_isolated_liq(0.1)
assert trade.isolated_liq == 0.1
assert trade.stop_loss == 0.08
assert trade.initial_stop_loss == 0.09
assert trade.initial_stop_loss == 0.08
trade.set_isolated_liq(0.07)
assert trade.isolated_liq == 0.07
assert trade.stop_loss == 0.07
assert trade.initial_stop_loss == 0.09
trade._set_stop_loss(0.1, (1.0/8.0))
assert trade.isolated_liq == 0.07
assert trade.stop_loss == 0.07
assert trade.initial_stop_loss == 0.09
assert trade.initial_stop_loss == 0.08
# Stop doesn't move stop higher
trade._set_stop_loss(0.1, (1.0/9.0))
assert trade.isolated_liq == 0.07
assert trade.stop_loss == 0.07
assert trade.initial_stop_loss == 0.08
@pytest.mark.parametrize('exchange,is_short,lev,minutes,rate,interest,trading_mode', [