Simplify and align adjust_trade_position interface
This commit is contained in:
parent
192bc868a7
commit
7c464f3237
@ -675,20 +675,35 @@ class DigDeeperStrategy(IStrategy):
|
|||||||
return proposed_stake / self.max_dca_multiplier
|
return proposed_stake / self.max_dca_multiplier
|
||||||
|
|
||||||
def adjust_trade_position(self, trade: Trade, current_time: datetime,
|
def adjust_trade_position(self, trade: Trade, current_time: datetime,
|
||||||
current_rate: float, current_profit: float, min_stake: Optional[float],
|
current_rate: float, current_profit: float,
|
||||||
max_stake: float, **kwargs):
|
min_stake: Optional[float], max_stake: float,
|
||||||
|
current_entry_rate: float, current_exit_rate: float,
|
||||||
|
current_entry_profit: float, current_exit_profit: float,
|
||||||
|
**kwargs) -> Optional[float]:
|
||||||
"""
|
"""
|
||||||
Custom trade adjustment logic, returning the stake amount that a trade should be increased.
|
Custom trade adjustment logic, returning the stake amount that a trade should be
|
||||||
This means extra buy orders with additional fees.
|
increased or decreased.
|
||||||
|
This means extra buy or sell orders with additional fees.
|
||||||
|
Only called when `position_adjustment_enable` is set to True.
|
||||||
|
|
||||||
|
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
||||||
|
|
||||||
|
When not implemented by a strategy, returns None
|
||||||
|
|
||||||
:param trade: trade object.
|
:param trade: trade object.
|
||||||
:param current_time: datetime object, containing the current datetime
|
:param current_time: datetime object, containing the current datetime
|
||||||
:param current_rate: Current buy rate.
|
:param current_rate: Current buy rate.
|
||||||
:param current_profit: Current profit (as ratio), calculated based on current_rate.
|
:param current_profit: Current profit (as ratio), calculated based on current_rate.
|
||||||
:param min_stake: Minimal stake size allowed by exchange.
|
:param min_stake: Minimal stake size allowed by exchange (for both entries and exits)
|
||||||
:param max_stake: Balance available for trading.
|
:param max_stake: Maximum stake allowed (either through balance, or by exchange limits).
|
||||||
|
:param current_entry_rate: Current rate using entry pricing.
|
||||||
|
:param current_exit_rate: Current rate using exit pricing.
|
||||||
|
:param current_entry_profit: Current profit using entry pricing.
|
||||||
|
:param current_exit_profit: Current profit using exit pricing.
|
||||||
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
||||||
:return float: Stake amount to adjust your trade
|
:return float: Stake amount to adjust your trade,
|
||||||
|
Positive values to increase position, Negative values to decrease position.
|
||||||
|
Return None for no action.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if current_profit > -0.05:
|
if current_profit > -0.05:
|
||||||
|
@ -526,7 +526,6 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
current_exit_rate,
|
current_exit_rate,
|
||||||
self.strategy.stoploss)
|
self.strategy.stoploss)
|
||||||
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)
|
||||||
max_exit_stake = self.exchange.get_max_pair_stake_amount(trade.pair, current_exit_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}")
|
||||||
stake_amount = strategy_safe_wrapper(self.strategy.adjust_trade_position,
|
stake_amount = strategy_safe_wrapper(self.strategy.adjust_trade_position,
|
||||||
@ -535,10 +534,7 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
current_profit=current_entry_profit, min_stake=min_entry_stake,
|
current_profit=current_entry_profit, min_stake=min_entry_stake,
|
||||||
max_stake=min(max_entry_stake, stake_available),
|
max_stake=min(max_entry_stake, stake_available),
|
||||||
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
|
||||||
min_entry_stake=min_entry_stake, min_exit_stake=min_exit_stake,
|
|
||||||
max_entry_stake=min(max_entry_stake, stake_available),
|
|
||||||
max_exit_stake=min(max_exit_stake, stake_available)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if stake_amount is not None and stake_amount > 0.0:
|
if stake_amount is not None and stake_amount > 0.0:
|
||||||
@ -555,10 +551,9 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
|
|
||||||
if stake_amount is not None and stake_amount < 0.0:
|
if stake_amount is not None and stake_amount < 0.0:
|
||||||
# We should decrease our position
|
# We should decrease our position
|
||||||
# Strategy should return value as Decimal for accuracy.
|
|
||||||
amount = abs(float(Decimal(stake_amount) / Decimal(current_exit_rate)))
|
amount = abs(float(Decimal(stake_amount) / Decimal(current_exit_rate)))
|
||||||
if (trade.amount - amount) * current_exit_rate < min_exit_stake:
|
if (trade.amount - amount) * current_exit_rate < min_exit_stake:
|
||||||
logger.info('Remaining amount would be too small')
|
logger.info('Remaining amount would be too small.')
|
||||||
return
|
return
|
||||||
if amount > trade.amount:
|
if amount > trade.amount:
|
||||||
logger.info(
|
logger.info(
|
||||||
|
@ -506,8 +506,7 @@ class Backtesting:
|
|||||||
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,
|
||||||
max_entry_stake=min(max_stake, stake_available),
|
current_entry_profit=current_profit, current_exit_profit=current_profit)
|
||||||
max_exit_stake=min(max_stake, stake_available))
|
|
||||||
|
|
||||||
# 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:
|
||||||
|
@ -456,10 +456,13 @@ class IStrategy(ABC, HyperStrategyMixin):
|
|||||||
def adjust_trade_position(self, trade: Trade, current_time: datetime,
|
def adjust_trade_position(self, trade: Trade, current_time: datetime,
|
||||||
current_rate: float, current_profit: float,
|
current_rate: float, current_profit: float,
|
||||||
min_stake: Optional[float], max_stake: 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) -> Optional[float]:
|
**kwargs) -> Optional[float]:
|
||||||
"""
|
"""
|
||||||
Custom trade adjustment logic, returning the stake amount that a trade should be increased.
|
Custom trade adjustment logic, returning the stake amount that a trade should be
|
||||||
This means extra buy orders with additional fees.
|
increased or decreased.
|
||||||
|
This means extra buy or sell orders with additional fees.
|
||||||
Only called when `position_adjustment_enable` is set to True.
|
Only called when `position_adjustment_enable` is set to True.
|
||||||
|
|
||||||
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
||||||
@ -470,10 +473,16 @@ class IStrategy(ABC, HyperStrategyMixin):
|
|||||||
:param current_time: datetime object, containing the current datetime
|
:param current_time: datetime object, containing the current datetime
|
||||||
:param current_rate: Current buy rate.
|
:param current_rate: Current buy rate.
|
||||||
:param current_profit: Current profit (as ratio), calculated based on current_rate.
|
:param current_profit: Current profit (as ratio), calculated based on current_rate.
|
||||||
:param min_stake: Minimal stake size allowed by exchange.
|
:param min_stake: Minimal stake size allowed by exchange (for both entries and exits)
|
||||||
:param max_stake: Balance available for trading.
|
:param max_stake: Maximum stake allowed (either through balance, or by exchange limits).
|
||||||
|
:param current_entry_rate: Current rate using entry pricing.
|
||||||
|
:param current_exit_rate: Current rate using exit pricing.
|
||||||
|
:param current_entry_profit: Current profit using entry pricing.
|
||||||
|
:param current_exit_profit: Current profit using exit pricing.
|
||||||
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
||||||
:return float: Stake amount to adjust your trade
|
:return float: Stake amount to adjust your trade,
|
||||||
|
Positive values to increase position, Negative values to decrease position.
|
||||||
|
Return None for no action.
|
||||||
"""
|
"""
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -243,12 +243,16 @@ def check_exit_timeout(self, pair: str, trade: 'Trade', order: 'Order',
|
|||||||
"""
|
"""
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def adjust_trade_position(self, trade: 'Trade', current_time: 'datetime',
|
def adjust_trade_position(self, trade: Trade, current_time: datetime,
|
||||||
current_rate: float, current_profit: float, min_stake: Optional[float],
|
current_rate: float, current_profit: float,
|
||||||
max_stake: float, **kwargs) -> 'Optional[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) -> Optional[float]:
|
||||||
"""
|
"""
|
||||||
Custom trade adjustment logic, returning the stake amount that a trade should be increased.
|
Custom trade adjustment logic, returning the stake amount that a trade should be
|
||||||
This means extra buy orders with additional fees.
|
increased or decreased.
|
||||||
|
This means extra buy or sell orders with additional fees.
|
||||||
Only called when `position_adjustment_enable` is set to True.
|
Only called when `position_adjustment_enable` is set to True.
|
||||||
|
|
||||||
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
||||||
@ -259,10 +263,16 @@ def adjust_trade_position(self, trade: 'Trade', current_time: 'datetime',
|
|||||||
:param current_time: datetime object, containing the current datetime
|
:param current_time: datetime object, containing the current datetime
|
||||||
:param current_rate: Current buy rate.
|
:param current_rate: Current buy rate.
|
||||||
:param current_profit: Current profit (as ratio), calculated based on current_rate.
|
:param current_profit: Current profit (as ratio), calculated based on current_rate.
|
||||||
:param min_stake: Minimal stake size allowed by exchange.
|
:param min_stake: Minimal stake size allowed by exchange (for both entries and exits)
|
||||||
:param max_stake: Balance available for trading.
|
:param max_stake: Maximum stake allowed (either through balance, or by exchange limits).
|
||||||
|
:param current_entry_rate: Current rate using entry pricing.
|
||||||
|
:param current_exit_rate: Current rate using exit pricing.
|
||||||
|
:param current_entry_profit: Current profit using entry pricing.
|
||||||
|
:param current_exit_profit: Current profit using exit pricing.
|
||||||
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
||||||
:return float: Stake amount to adjust your trade
|
:return float: Stake amount to adjust your trade,
|
||||||
|
Positive values to increase position, Negative values to decrease position.
|
||||||
|
Return None for no action.
|
||||||
"""
|
"""
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user