mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
Add stoploss or liquidation property
This commit is contained in:
parent
4da96bc511
commit
845cecd38f
|
@ -302,6 +302,16 @@ class LocalTrade():
|
|||
# Futures properties
|
||||
funding_fees: Optional[float] = None
|
||||
|
||||
@property
|
||||
def stoploss_or_liquidation(self) -> float:
|
||||
if self.liquidation_price:
|
||||
if self.is_short:
|
||||
return min(self.stop_loss, self.liquidation_price)
|
||||
else:
|
||||
return max(self.stop_loss, self.liquidation_price)
|
||||
|
||||
return self.stop_loss
|
||||
|
||||
@property
|
||||
def buy_tag(self) -> Optional[str]:
|
||||
"""
|
||||
|
|
|
@ -1063,13 +1063,6 @@ class IStrategy(ABC, HyperStrategyMixin):
|
|||
f"stoploss is {trade.stop_loss:.6f}, "
|
||||
f"initial stoploss was at {trade.initial_stop_loss:.6f}, "
|
||||
f"trade opened at {trade.open_rate:.6f}")
|
||||
new_stoploss = (
|
||||
trade.stop_loss + trade.initial_stop_loss
|
||||
if trade.is_short else
|
||||
trade.stop_loss - trade.initial_stop_loss
|
||||
)
|
||||
logger.debug(f"{trade.pair} - Trailing stop saved "
|
||||
f"{new_stoploss:.6f}")
|
||||
|
||||
return ExitCheckTuple(exit_type=exit_type)
|
||||
|
||||
|
|
|
@ -148,6 +148,7 @@ def test_set_stop_loss_isolated_liq(fee):
|
|||
assert trade.liquidation_price == 0.11
|
||||
assert pytest.approx(trade.stop_loss) == 1.994999
|
||||
assert trade.initial_stop_loss == 1.8
|
||||
assert trade.stoploss_or_liquidation == trade.stop_loss
|
||||
|
||||
trade.stop_loss = None
|
||||
trade.liquidation_price = None
|
||||
|
@ -158,6 +159,7 @@ def test_set_stop_loss_isolated_liq(fee):
|
|||
assert trade.liquidation_price is None
|
||||
assert trade.stop_loss == 1.9
|
||||
assert trade.initial_stop_loss == 1.9
|
||||
assert trade.stoploss_or_liquidation == 1.9
|
||||
|
||||
trade.is_short = True
|
||||
trade.recalc_open_trade_value()
|
||||
|
@ -174,11 +176,13 @@ def test_set_stop_loss_isolated_liq(fee):
|
|||
assert trade.liquidation_price == 3.09
|
||||
assert trade.stop_loss == 2.2
|
||||
assert trade.initial_stop_loss == 2.2
|
||||
assert trade.stoploss_or_liquidation == 2.2
|
||||
|
||||
trade.set_isolated_liq(3.1)
|
||||
assert trade.liquidation_price == 3.1
|
||||
assert trade.stop_loss == 2.2
|
||||
assert trade.initial_stop_loss == 2.2
|
||||
assert trade.stoploss_or_liquidation == 2.2
|
||||
|
||||
trade.set_isolated_liq(3.8)
|
||||
assert trade.liquidation_price == 3.8
|
||||
|
@ -193,10 +197,14 @@ def test_set_stop_loss_isolated_liq(fee):
|
|||
assert trade.initial_stop_loss == 2.2
|
||||
|
||||
# Stoploss does move lower
|
||||
trade.set_isolated_liq(1.5)
|
||||
trade.adjust_stop_loss(1.8, 0.1)
|
||||
assert trade.liquidation_price == 3.8
|
||||
assert trade.liquidation_price == 1.5
|
||||
assert pytest.approx(trade.stop_loss) == 1.89
|
||||
assert trade.initial_stop_loss == 2.2
|
||||
assert trade.stoploss_or_liquidation == 1.5
|
||||
|
||||
|
||||
|
||||
|
||||
@pytest.mark.parametrize('exchange,is_short,lev,minutes,rate,interest,trading_mode', [
|
||||
|
|
Loading…
Reference in New Issue
Block a user