CUSTOM_SELL -> CUSTOM_EXIT

This commit is contained in:
Sam Germain 2022-01-04 23:12:05 -06:00
parent 26e54fb035
commit c830db62f6
4 changed files with 11 additions and 11 deletions

View File

@ -12,7 +12,7 @@ class ExitType(Enum):
EXIT_SIGNAL = "exit_signal"
FORCE_EXIT = "force_exit"
EMERGENCY_EXIT = "emergency_sell"
CUSTOM_SELL = "custom_sell"
CUSTOM_EXIT = "custom_sell"
NONE = ""
def __str__(self):

View File

@ -395,7 +395,7 @@ class Backtesting:
closerate = self._get_close_rate(sell_row, trade, sell, trade_dur)
# call the custom exit price,with default value as previous closerate
current_profit = trade.calc_profit_ratio(closerate)
if sell.exit_type in (ExitType.EXIT_SIGNAL, ExitType.CUSTOM_SELL):
if sell.exit_type in (ExitType.EXIT_SIGNAL, ExitType.CUSTOM_EXIT):
# Custom exit pricing only for sell-signals
closerate = strategy_safe_wrapper(self.strategy.custom_exit_price,
default_retval=closerate)(

View File

@ -27,7 +27,7 @@ from freqtrade.wallets import Wallets
logger = logging.getLogger(__name__)
CUSTOM_SELL_MAX_LENGTH = 64
CUSTOM_EXIT_MAX_LENGTH = 64
class ExitCheckTuple:
@ -802,16 +802,16 @@ class IStrategy(ABC, HyperStrategyMixin):
pair=trade.pair, trade=trade, current_time=date, current_rate=current_rate,
current_profit=current_profit)
if custom_reason:
exit_signal = ExitType.CUSTOM_SELL
exit_signal = ExitType.CUSTOM_EXIT
if isinstance(custom_reason, str):
if len(custom_reason) > CUSTOM_SELL_MAX_LENGTH:
if len(custom_reason) > CUSTOM_EXIT_MAX_LENGTH:
logger.warning(f'Custom {trade_type} reason returned from '
f'custom_{trade_type} is too long and was trimmed'
f'to {CUSTOM_SELL_MAX_LENGTH} characters.')
custom_reason = custom_reason[:CUSTOM_SELL_MAX_LENGTH]
f'to {CUSTOM_EXIT_MAX_LENGTH} characters.')
custom_reason = custom_reason[:CUSTOM_EXIT_MAX_LENGTH]
else:
custom_reason = None
if exit_signal in (ExitType.CUSTOM_SELL, ExitType.EXIT_SIGNAL):
if exit_signal in (ExitType.CUSTOM_EXIT, ExitType.EXIT_SIGNAL):
logger.debug(f"{trade.pair} - Sell signal received. "
f"exit_type=ExitType.{exit_signal.name}" +
(f", custom_reason={custom_reason}" if custom_reason else ""))

View File

@ -487,7 +487,7 @@ def test_custom_sell(default_conf, fee, caplog) -> None:
enter=False, exit_=False,
low=None, high=None)
assert res.sell_flag is True
assert res.exit_type == ExitType.CUSTOM_SELL
assert res.exit_type == ExitType.CUSTOM_EXIT
assert res.exit_reason == 'custom_sell'
strategy.custom_sell = MagicMock(return_value='hello world')
@ -495,7 +495,7 @@ def test_custom_sell(default_conf, fee, caplog) -> None:
res = strategy.should_exit(trade, 1, now,
enter=False, exit_=False,
low=None, high=None)
assert res.exit_type == ExitType.CUSTOM_SELL
assert res.exit_type == ExitType.CUSTOM_EXIT
assert res.sell_flag is True
assert res.exit_reason == 'hello world'
@ -504,7 +504,7 @@ def test_custom_sell(default_conf, fee, caplog) -> None:
res = strategy.should_exit(trade, 1, now,
enter=False, exit_=False,
low=None, high=None)
assert res.exit_type == ExitType.CUSTOM_SELL
assert res.exit_type == ExitType.CUSTOM_EXIT
assert res.sell_flag is True
assert res.exit_reason == 'h' * 64
assert log_has_re('Custom sell reason returned from custom_sell is too long.*', caplog)