Improve method wording for liquidation price setter

This commit is contained in:
Matthias 2022-07-30 09:19:48 +02:00
parent dba7a7257d
commit d046f0cc5e
4 changed files with 14 additions and 16 deletions

View File

@ -1085,7 +1085,7 @@ class FreqtradeBot(LoggingMixin):
if (trade.is_open if (trade.is_open
and stoploss_order and stoploss_order
and stoploss_order['status'] in ('canceled', 'cancelled')): and stoploss_order['status'] in ('canceled', 'cancelled')):
if self.create_stoploss_order(trade=trade, stop_price=trade.stop_loss): if self.create_stoploss_order(trade=trade, stop_price=trade.stoploss_or_liquidation):
return False return False
else: else:
trade.stoploss_order_id = None trade.stoploss_order_id = None
@ -1662,7 +1662,7 @@ class FreqtradeBot(LoggingMixin):
trade = self.cancel_stoploss_on_exchange(trade) trade = self.cancel_stoploss_on_exchange(trade)
# 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_liquidation_price(self.exchange.get_liquidation_price(
leverage=trade.leverage, leverage=trade.leverage,
pair=trade.pair, pair=trade.pair,
amount=trade.amount, amount=trade.amount,

View File

@ -814,7 +814,7 @@ class Backtesting:
trade.adjust_stop_loss(trade.open_rate, self.strategy.stoploss, initial=True) trade.adjust_stop_loss(trade.open_rate, self.strategy.stoploss, initial=True)
trade.set_isolated_liq(self.exchange.get_liquidation_price( trade.set_liquidation_price(self.exchange.get_liquidation_price(
pair=pair, pair=pair,
open_rate=propose_rate, open_rate=propose_rate,
amount=amount, amount=amount,

View File

@ -507,7 +507,7 @@ class LocalTrade():
self.max_rate = max(current_price, self.max_rate or self.open_rate) self.max_rate = max(current_price, self.max_rate or self.open_rate)
self.min_rate = min(current_price_low, self.min_rate or self.open_rate) self.min_rate = min(current_price_low, self.min_rate or self.open_rate)
def set_isolated_liq(self, liquidation_price: Optional[float]): def set_liquidation_price(self, liquidation_price: Optional[float]):
""" """
Method you should use to set self.liquidation price. Method you should use to set self.liquidation price.
Assures stop_loss is not passed the liquidation price Assures stop_loss is not passed the liquidation price

View File

@ -99,7 +99,7 @@ def test_enter_exit_side(fee, is_short):
@pytest.mark.usefixtures("init_persistence") @pytest.mark.usefixtures("init_persistence")
def test_set_stop_loss_isolated_liq(fee): def test_set_stop_loss_liquidation(fee):
trade = Trade( trade = Trade(
id=2, id=2,
pair='ADA/USDT', pair='ADA/USDT',
@ -115,7 +115,7 @@ def test_set_stop_loss_isolated_liq(fee):
leverage=2.0, leverage=2.0,
trading_mode=margin trading_mode=margin
) )
trade.set_isolated_liq(0.09) trade.set_liquidation_price(0.09)
assert trade.liquidation_price == 0.09 assert trade.liquidation_price == 0.09
assert trade.stop_loss is None assert trade.stop_loss is None
assert trade.initial_stop_loss is None assert trade.initial_stop_loss is None
@ -125,12 +125,12 @@ def test_set_stop_loss_isolated_liq(fee):
assert trade.stop_loss == 1.8 assert trade.stop_loss == 1.8
assert trade.initial_stop_loss == 1.8 assert trade.initial_stop_loss == 1.8
trade.set_isolated_liq(0.08) trade.set_liquidation_price(0.08)
assert trade.liquidation_price == 0.08 assert trade.liquidation_price == 0.08
assert trade.stop_loss == 1.8 assert trade.stop_loss == 1.8
assert trade.initial_stop_loss == 1.8 assert trade.initial_stop_loss == 1.8
trade.set_isolated_liq(0.11) trade.set_liquidation_price(0.11)
trade.adjust_stop_loss(2.0, 0.2) trade.adjust_stop_loss(2.0, 0.2)
assert trade.liquidation_price == 0.11 assert trade.liquidation_price == 0.11
# Stoploss does not change from liquidation price # Stoploss does not change from liquidation price
@ -167,7 +167,7 @@ def test_set_stop_loss_isolated_liq(fee):
trade.initial_stop_loss = None trade.initial_stop_loss = None
trade.initial_stop_loss_pct = None trade.initial_stop_loss_pct = None
trade.set_isolated_liq(3.09) trade.set_liquidation_price(3.09)
assert trade.liquidation_price == 3.09 assert trade.liquidation_price == 3.09
assert trade.stop_loss is None assert trade.stop_loss is None
assert trade.initial_stop_loss is None assert trade.initial_stop_loss is None
@ -178,13 +178,13 @@ def test_set_stop_loss_isolated_liq(fee):
assert trade.initial_stop_loss == 2.2 assert trade.initial_stop_loss == 2.2
assert trade.stoploss_or_liquidation == 2.2 assert trade.stoploss_or_liquidation == 2.2
trade.set_isolated_liq(3.1) trade.set_liquidation_price(3.1)
assert trade.liquidation_price == 3.1 assert trade.liquidation_price == 3.1
assert trade.stop_loss == 2.2 assert trade.stop_loss == 2.2
assert trade.initial_stop_loss == 2.2 assert trade.initial_stop_loss == 2.2
assert trade.stoploss_or_liquidation == 2.2 assert trade.stoploss_or_liquidation == 2.2
trade.set_isolated_liq(3.8) trade.set_liquidation_price(3.8)
assert trade.liquidation_price == 3.8 assert trade.liquidation_price == 3.8
# Stoploss does not change from liquidation price # Stoploss does not change from liquidation price
assert trade.stop_loss == 2.2 assert trade.stop_loss == 2.2
@ -197,7 +197,7 @@ def test_set_stop_loss_isolated_liq(fee):
assert trade.initial_stop_loss == 2.2 assert trade.initial_stop_loss == 2.2
# Stoploss does move lower # Stoploss does move lower
trade.set_isolated_liq(1.5) trade.set_liquidation_price(1.5)
trade.adjust_stop_loss(1.8, 0.1) trade.adjust_stop_loss(1.8, 0.1)
assert trade.liquidation_price == 1.5 assert trade.liquidation_price == 1.5
assert pytest.approx(trade.stop_loss) == 1.89 assert pytest.approx(trade.stop_loss) == 1.89
@ -205,8 +205,6 @@ def test_set_stop_loss_isolated_liq(fee):
assert trade.stoploss_or_liquidation == 1.5 assert trade.stoploss_or_liquidation == 1.5
@pytest.mark.parametrize('exchange,is_short,lev,minutes,rate,interest,trading_mode', [ @pytest.mark.parametrize('exchange,is_short,lev,minutes,rate,interest,trading_mode', [
("binance", False, 3, 10, 0.0005, round(0.0008333333333333334, 8), margin), ("binance", False, 3, 10, 0.0005, round(0.0008333333333333334, 8), margin),
("binance", True, 3, 10, 0.0005, 0.000625, margin), ("binance", True, 3, 10, 0.0005, 0.000625, margin),
@ -1633,7 +1631,7 @@ def test_adjust_stop_loss_short(fee):
assert trade.initial_stop_loss_pct == -0.05 assert trade.initial_stop_loss_pct == -0.05
assert trade.stop_loss_pct == -0.1 assert trade.stop_loss_pct == -0.1
# Liquidation price is lower than stoploss - so liquidation would trigger first. # Liquidation price is lower than stoploss - so liquidation would trigger first.
trade.set_isolated_liq(0.63) trade.set_liquidation_price(0.63)
trade.adjust_stop_loss(0.59, -0.1) trade.adjust_stop_loss(0.59, -0.1)
assert trade.stop_loss == 0.649 assert trade.stop_loss == 0.649
assert trade.liquidation_price == 0.63 assert trade.liquidation_price == 0.63
@ -2033,7 +2031,7 @@ def test_stoploss_reinitialization_short(default_conf, fee):
assert trade_adj.initial_stop_loss == 1.01 assert trade_adj.initial_stop_loss == 1.01
assert trade_adj.initial_stop_loss_pct == -0.05 assert trade_adj.initial_stop_loss_pct == -0.05
# Stoploss can't go above liquidation price # Stoploss can't go above liquidation price
trade_adj.set_isolated_liq(0.985) trade_adj.set_liquidation_price(0.985)
trade.adjust_stop_loss(0.9799, -0.05) trade.adjust_stop_loss(0.9799, -0.05)
assert trade_adj.stop_loss == 0.989699 assert trade_adj.stop_loss == 0.989699
assert trade_adj.liquidation_price == 0.985 assert trade_adj.liquidation_price == 0.985