Simplify leverage_prep interface

This commit is contained in:
Matthias 2022-02-28 19:34:10 +01:00
parent 8e2d3445a7
commit 1d27cbd01f
2 changed files with 3 additions and 6 deletions

View File

@ -695,17 +695,12 @@ class Backtesting:
trading_mode=self.trading_mode, trading_mode=self.trading_mode,
leverage=leverage, leverage=leverage,
interest_rate=interest_rate, interest_rate=interest_rate,
isolated_liq=isolated_liq,
orders=[], orders=[],
) )
trade.adjust_stop_loss(trade.open_rate, self.strategy.stoploss, initial=True) trade.adjust_stop_loss(trade.open_rate, self.strategy.stoploss, initial=True)
if self.trading_mode == TradingMode.FUTURES: if self.trading_mode == TradingMode.FUTURES:
if isolated_liq is None:
raise OperationalException(
f'isolated_liq is none for {pair} while trading futures, '
'this should never happen')
trade.set_isolated_liq(isolated_liq) trade.set_isolated_liq(isolated_liq)
order = Order( order = Order(

View File

@ -425,11 +425,13 @@ class LocalTrade():
self.stop_loss_pct = -1 * abs(percent) self.stop_loss_pct = -1 * abs(percent)
self.stoploss_last_update = datetime.utcnow() self.stoploss_last_update = datetime.utcnow()
def set_isolated_liq(self, isolated_liq: float): def set_isolated_liq(self, isolated_liq: 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
""" """
if not isolated_liq:
return
if self.stop_loss is not None: if self.stop_loss is not None:
if self.is_short: if self.is_short:
self.stop_loss = min(self.stop_loss, isolated_liq) self.stop_loss = min(self.stop_loss, isolated_liq)