Don't modify leverage through DCA

This commit is contained in:
Matthias 2022-02-21 19:27:38 +01:00
parent 536f54cfc6
commit 1b6548c8d8
3 changed files with 30 additions and 25 deletions

View File

@ -643,18 +643,21 @@ class FreqtradeBot(LoggingMixin):
if not stake_amount: if not stake_amount:
return False return False
if not pos_adjust:
max_leverage = self.exchange.get_max_leverage(pair, stake_amount) max_leverage = self.exchange.get_max_leverage(pair, stake_amount)
leverage = strategy_safe_wrapper(self.strategy.leverage, default_retval=1.0)( leverage = strategy_safe_wrapper(self.strategy.leverage, default_retval=1.0)(
pair=pair, pair=pair,
current_time=datetime.now(timezone.utc), current_time=datetime.now(timezone.utc),
current_rate=enter_limit_requested, current_rate=enter_limit_requested,
proposed_leverage=1.0, proposed_leverage=1.0,
max_leverage=max_leverage, max_leverage=max_leverage,
side=trade_side, side=trade_side,
) if self.trading_mode != TradingMode.SPOT else 1.0 ) if self.trading_mode != TradingMode.SPOT else 1.0
# Cap leverage between 1.0 and max_leverage. # Cap leverage between 1.0 and max_leverage.
leverage = min(max(leverage, 1.0), max_leverage) leverage = min(max(leverage, 1.0), max_leverage)
else:
# Changing leverage currently not possible
leverage = trade.leverage if trade else 1.0
if pos_adjust: if pos_adjust:
logger.info(f"Position adjust: about to create a new order for {pair} with stake: " logger.info(f"Position adjust: about to create a new order for {pair} with stake: "
f"{stake_amount} for {trade}") f"{stake_amount} for {trade}")

View File

@ -639,17 +639,20 @@ class Backtesting:
# If not pos adjust, trade is None # If not pos adjust, trade is None
return trade return trade
max_leverage = self.exchange.get_max_leverage(pair, stake_amount) if not pos_adjust:
leverage = strategy_safe_wrapper(self.strategy.leverage, default_retval=1.0)( max_leverage = self.exchange.get_max_leverage(pair, stake_amount)
pair=pair, leverage = strategy_safe_wrapper(self.strategy.leverage, default_retval=1.0)(
current_time=current_time, pair=pair,
current_rate=row[OPEN_IDX], current_time=current_time,
proposed_leverage=1.0, current_rate=row[OPEN_IDX],
max_leverage=max_leverage, proposed_leverage=1.0,
side=direction, max_leverage=max_leverage,
) if self._can_short else 1.0 side=direction,
# Cap leverage between 1.0 and max_leverage. ) if self._can_short else 1.0
leverage = min(max(leverage, 1.0), max_leverage) # Cap leverage between 1.0 and max_leverage.
leverage = min(max(leverage, 1.0), max_leverage)
else:
leverage = trade.leverage if trade else 1.0
order_type = self.strategy.order_types['buy'] order_type = self.strategy.order_types['buy']
time_in_force = self.strategy.order_time_in_force['buy'] time_in_force = self.strategy.order_time_in_force['buy']

View File

@ -889,8 +889,7 @@ class LocalTrade():
total_stake += tmp_price * tmp_amount total_stake += tmp_price * tmp_amount
if total_amount > 0: if total_amount > 0:
# TODO-lev: This should update leverage as well - # Leverage not updated, as we don't allow changing leverage through DCA at the moment.
# as averaged trades might have different leverage
self.open_rate = total_stake / total_amount self.open_rate = total_stake / total_amount
self.stake_amount = total_stake self.stake_amount = total_stake
self.amount = total_amount self.amount = total_amount