Move response handling to interface wrappermethod

This commit is contained in:
Matthias
2024-01-28 20:21:47 +01:00
parent 535ff387ff
commit 830a004dfd
3 changed files with 34 additions and 21 deletions

View File

@@ -645,8 +645,7 @@ class FreqtradeBot(LoggingMixin):
max_entry_stake = self.exchange.get_max_pair_stake_amount(trade.pair, current_entry_rate) max_entry_stake = self.exchange.get_max_pair_stake_amount(trade.pair, current_entry_rate)
stake_available = self.wallets.get_available_stake_amount() stake_available = self.wallets.get_available_stake_amount()
logger.debug(f"Calling adjust_trade_position for pair {trade.pair}") logger.debug(f"Calling adjust_trade_position for pair {trade.pair}")
resp = strategy_safe_wrapper(self.strategy.adjust_trade_position, stake_amount, order_tag = self.strategy._adjust_trade_position_internal(
default_retval=None, supress_error=True)(
trade=trade, trade=trade,
current_time=datetime.now(timezone.utc), current_rate=current_entry_rate, current_time=datetime.now(timezone.utc), current_rate=current_entry_rate,
current_profit=current_entry_profit, min_stake=min_entry_stake, current_profit=current_entry_profit, min_stake=min_entry_stake,
@@ -654,14 +653,6 @@ class FreqtradeBot(LoggingMixin):
current_entry_rate=current_entry_rate, current_exit_rate=current_exit_rate, current_entry_rate=current_entry_rate, current_exit_rate=current_exit_rate,
current_entry_profit=current_entry_profit, current_exit_profit=current_exit_profit current_entry_profit=current_entry_profit, current_exit_profit=current_exit_profit
) )
order_tag = ''
if isinstance(resp, tuple):
if len(resp) >= 1:
stake_amount = resp[0]
if len(resp) > 1:
order_tag = resp[1] or ''
else:
stake_amount = resp
if stake_amount is not None and stake_amount > 0.0: if stake_amount is not None and stake_amount > 0.0:
# We should increase our position # We should increase our position

View File

@@ -537,22 +537,14 @@ class Backtesting:
min_stake = self.exchange.get_min_pair_stake_amount(trade.pair, current_rate, -0.1) min_stake = self.exchange.get_min_pair_stake_amount(trade.pair, current_rate, -0.1)
max_stake = self.exchange.get_max_pair_stake_amount(trade.pair, current_rate) max_stake = self.exchange.get_max_pair_stake_amount(trade.pair, current_rate)
stake_available = self.wallets.get_available_stake_amount() stake_available = self.wallets.get_available_stake_amount()
resp = strategy_safe_wrapper(self.strategy.adjust_trade_position, stake_amount, order_tag = self.strategy._adjust_trade_position_internal(
default_retval=None, supress_error=True)(
trade=trade, # type: ignore[arg-type] trade=trade, # type: ignore[arg-type]
current_time=current_time, current_rate=current_rate, current_time=current_time, current_rate=current_rate,
current_profit=current_profit, min_stake=min_stake, current_profit=current_profit, min_stake=min_stake,
max_stake=min(max_stake, stake_available), max_stake=min(max_stake, stake_available),
current_entry_rate=current_rate, current_exit_rate=current_rate, current_entry_rate=current_rate, current_exit_rate=current_rate,
current_entry_profit=current_profit, current_exit_profit=current_profit) current_entry_profit=current_profit, current_exit_profit=current_profit
order_tag = '' )
if isinstance(resp, tuple):
if len(resp) >= 1:
stake_amount = resp[0]
if len(resp) > 1:
order_tag = resp[1] or ''
else:
stake_amount = resp
# Check if we should increase our position # Check if we should increase our position
if stake_amount is not None and stake_amount > 0.0: if stake_amount is not None and stake_amount > 0.0:

View File

@@ -727,6 +727,36 @@ class IStrategy(ABC, HyperStrategyMixin):
_ft_stop_uses_after_fill = False _ft_stop_uses_after_fill = False
def _adjust_trade_position_internal(
self, trade: Trade, current_time: datetime,
current_rate: float, current_profit: float,
min_stake: Optional[float], max_stake: float,
current_entry_rate: float, current_exit_rate: float,
current_entry_profit: float, current_exit_profit: float,
**kwargs
) -> Tuple[Optional[float], str]:
"""
wrapper around adjust_trade_position to handle the return value
"""
resp = strategy_safe_wrapper(self.adjust_trade_position,
default_retval=(None, ''), supress_error=True)(
trade=trade, current_time=current_time,
current_rate=current_rate, current_profit=current_profit,
min_stake=min_stake, max_stake=max_stake,
current_entry_rate=current_entry_rate, current_exit_rate=current_exit_rate,
current_entry_profit=current_entry_profit, current_exit_profit=current_exit_profit,
**kwargs
)
order_tag = ''
if isinstance(resp, tuple):
if len(resp) >= 1:
stake_amount = resp[0]
if len(resp) > 1:
order_tag = resp[1] or ''
else:
stake_amount = resp
return stake_amount, order_tag
def __informative_pairs_freqai(self) -> ListPairsWithTimeframes: def __informative_pairs_freqai(self) -> ListPairsWithTimeframes:
""" """
Create informative-pairs needed for FreqAI Create informative-pairs needed for FreqAI