Call "leverage" to determine leverage to be used.

This commit is contained in:
Matthias 2021-11-18 20:55:45 +01:00
parent 5a8824171c
commit 021d1b518c

View File

@ -443,13 +443,13 @@ class Backtesting:
stake_amount = self.wallets.get_trade_stake_amount(pair, None) stake_amount = self.wallets.get_trade_stake_amount(pair, None)
except DependencyException: except DependencyException:
return None return None
current_time = row[DATE_IDX].to_pydatetime()
min_stake_amount = self.exchange.get_min_pair_stake_amount(pair, row[OPEN_IDX], -0.05) or 0 min_stake_amount = self.exchange.get_min_pair_stake_amount(pair, row[OPEN_IDX], -0.05) or 0
max_stake_amount = self.wallets.get_available_stake_amount() max_stake_amount = self.wallets.get_available_stake_amount()
stake_amount = strategy_safe_wrapper(self.strategy.custom_stake_amount, stake_amount = strategy_safe_wrapper(self.strategy.custom_stake_amount,
default_retval=stake_amount)( default_retval=stake_amount)(
pair=pair, current_time=row[DATE_IDX].to_pydatetime(), current_rate=row[OPEN_IDX], pair=pair, current_time=current_time, current_rate=row[OPEN_IDX],
proposed_stake=stake_amount, min_stake=min_stake_amount, max_stake=max_stake_amount, proposed_stake=stake_amount, min_stake=min_stake_amount, max_stake=max_stake_amount,
side=direction) side=direction)
stake_amount = self.wallets.validate_stake_amount(pair, stake_amount, min_stake_amount) stake_amount = self.wallets.validate_stake_amount(pair, stake_amount, min_stake_amount)
@ -457,12 +457,21 @@ class Backtesting:
if not stake_amount: if not stake_amount:
return None return None
leverage = strategy_safe_wrapper(self.strategy.leverage, default_retval=1.0)(
pair=pair,
current_time=current_time,
current_rate=row[OPEN_IDX],
proposed_leverage=1.0,
max_leverage=self.exchange.get_max_leverage(pair, stake_amount),
side=direction,
) if self._can_short 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['sell'] time_in_force = self.strategy.order_time_in_force['sell']
# Confirm trade entry: # Confirm trade entry:
if not strategy_safe_wrapper(self.strategy.confirm_trade_entry, default_retval=True)( if not strategy_safe_wrapper(self.strategy.confirm_trade_entry, default_retval=True)(
pair=pair, order_type=order_type, amount=stake_amount, rate=row[OPEN_IDX], pair=pair, order_type=order_type, amount=stake_amount, rate=row[OPEN_IDX],
time_in_force=time_in_force, current_time=row[DATE_IDX].to_pydatetime(), time_in_force=time_in_force, current_time=current_time,
side=direction): side=direction):
return None return None
@ -472,7 +481,7 @@ class Backtesting:
trade = LocalTrade( trade = LocalTrade(
pair=pair, pair=pair,
open_rate=row[OPEN_IDX], open_rate=row[OPEN_IDX],
open_date=row[DATE_IDX].to_pydatetime(), open_date=current_time,
stake_amount=stake_amount, stake_amount=stake_amount,
amount=round(stake_amount / row[OPEN_IDX], 8), amount=round(stake_amount / row[OPEN_IDX], 8),
fee_open=self.fee, fee_open=self.fee,
@ -481,6 +490,7 @@ class Backtesting:
buy_tag=row[ENTER_TAG_IDX] if has_enter_tag else None, buy_tag=row[ENTER_TAG_IDX] if has_enter_tag else None,
exchange=self._exchange_name, exchange=self._exchange_name,
is_short=(direction == 'short'), is_short=(direction == 'short'),
leverage=leverage,
) )
return trade return trade
return None return None