Improve documentation on adjust_trade_position and position_adjustment_enable

This commit is contained in:
Reigo Reinmets
2021-12-11 17:14:04 +02:00
parent f97662e816
commit f11a40f144
8 changed files with 149 additions and 7 deletions

View File

@@ -102,6 +102,9 @@ class FreqtradeBot(LoggingMixin):
self._exit_lock = Lock()
LoggingMixin.__init__(self, logger, timeframe_to_seconds(self.strategy.timeframe))
# Is Position Adjustment enabled?
self.position_adjustment = bool(self.config.get('position_adjustment_enable', False))
def notify_status(self, msg: str) -> None:
"""
Public method for users of this class (worker, etc.) to send notifications
@@ -179,7 +182,7 @@ class FreqtradeBot(LoggingMixin):
self.exit_positions(trades)
# Check if we need to adjust our current positions before attempting to buy new trades.
if self.config.get('position_adjustment_enable', False):
if self.position_adjustment:
self.process_open_trade_positions()
# Then looking for buy opportunities

View File

@@ -118,6 +118,7 @@ class Backtesting:
# Add maximum startup candle count to configuration for informative pairs support
self.config['startup_candle_count'] = self.required_startup
self.exchange.validate_required_startup_candles(self.required_startup, self.timeframe)
self.position_adjustment = bool(self.config.get('position_adjustment_enable', False))
self.init_backtest()
def __del__(self):
@@ -353,7 +354,7 @@ class Backtesting:
def _get_adjust_trade_entry_for_candle(self, trade: LocalTrade, row: Tuple) -> Optional[LocalTrade]:
current_profit = trade.calc_profit_ratio(row[OPEN_IDX])
stake_amount = strategy_safe_wrapper(self.strategy.adjust_trade_position, default_retval=None)(
pair=trade.pair, trade=trade, current_time=row[DATE_IDX].to_pydatetime(),
current_rate=row[OPEN_IDX], current_profit=current_profit)
@@ -403,9 +404,9 @@ class Backtesting:
def _get_sell_trade_entry_for_candle(self, trade: LocalTrade,
sell_row: Tuple) -> Optional[LocalTrade]:
# Check if we need to adjust our current positions
if self.config.get('position_adjustment_enable', False):
if self.position_adjustment:
trade = self._get_adjust_trade_entry_for_candle(trade, sell_row)
sell_candle_time = sell_row[DATE_IDX].to_pydatetime()

View File

@@ -386,11 +386,12 @@ class IStrategy(ABC, HyperStrategyMixin):
current_time: datetime, current_rate: float, current_profit: float,
**kwargs) -> Optional[float]:
"""
Custom trade adjustment logic, returning the stake amount that a trade shold be either increased or decreased.
Custom trade adjustment logic, returning the stake amount that a trade should be increased.
This means extra buy orders with additional fees.
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
When not implemented by a strategy, returns 0.0
When not implemented by a strategy, returns None
:param pair: Pair that's currently analyzed
:param trade: trade object.