From c830db62f6c9168255557744a93835eaec29fb23 Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Tue, 4 Jan 2022 23:12:05 -0600 Subject: [PATCH] CUSTOM_SELL -> CUSTOM_EXIT --- freqtrade/enums/exittype.py | 2 +- freqtrade/optimize/backtesting.py | 2 +- freqtrade/strategy/interface.py | 12 ++++++------ tests/strategy/test_interface.py | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/freqtrade/enums/exittype.py b/freqtrade/enums/exittype.py index 3b03e5514..fa0b711c7 100644 --- a/freqtrade/enums/exittype.py +++ b/freqtrade/enums/exittype.py @@ -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): diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index 17a121ff2..81428c75f 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -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)( diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index c45425c88..336be0f0c 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -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 "")) diff --git a/tests/strategy/test_interface.py b/tests/strategy/test_interface.py index e1ce5799b..c24e46df0 100644 --- a/tests/strategy/test_interface.py +++ b/tests/strategy/test_interface.py @@ -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)