diff --git a/freqtrade/edge/edge_positioning.py b/freqtrade/edge/edge_positioning.py index ab72f9da3..724bb9fb3 100644 --- a/freqtrade/edge/edge_positioning.py +++ b/freqtrade/edge/edge_positioning.py @@ -464,7 +464,7 @@ class Edge: if len(ohlc_columns) - 1 < exit_index: break - exit_type = ExitType.SELL_SIGNAL + exit_type = ExitType.EXIT_SIGNAL exit_price = ohlc_columns[exit_index, 0] trade = {'pair': pair, diff --git a/freqtrade/enums/exittype.py b/freqtrade/enums/exittype.py index 36d2a4f9e..a1e5e21e2 100644 --- a/freqtrade/enums/exittype.py +++ b/freqtrade/enums/exittype.py @@ -9,7 +9,7 @@ class ExitType(Enum): STOP_LOSS = "stop_loss" STOPLOSS_ON_EXCHANGE = "stoploss_on_exchange" TRAILING_STOP_LOSS = "trailing_stop_loss" - SELL_SIGNAL = "sell_signal" + EXIT_SIGNAL = "sell_signal" FORCE_SELL = "force_sell" EMERGENCY_SELL = "emergency_sell" CUSTOM_SELL = "custom_sell" diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index 577a0de41..9fe706357 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.SELL_SIGNAL, ExitType.CUSTOM_SELL): + if sell.exit_type in (ExitType.EXIT_SIGNAL, ExitType.CUSTOM_SELL): # 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 eff13e953..eaf830fa1 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -795,7 +795,7 @@ class IStrategy(ABC, HyperStrategyMixin): pass elif self.use_exit_signal and not enter: if exit_: - sell_signal = ExitType.SELL_SIGNAL + sell_signal = ExitType.EXIT_SIGNAL else: trade_type = "exit_short" if trade.is_short else "sell" custom_reason = strategy_safe_wrapper(self.custom_sell, default_retval=False)( @@ -811,7 +811,7 @@ class IStrategy(ABC, HyperStrategyMixin): custom_reason = custom_reason[:CUSTOM_SELL_MAX_LENGTH] else: custom_reason = None - if sell_signal in (ExitType.CUSTOM_SELL, ExitType.SELL_SIGNAL): + if sell_signal in (ExitType.CUSTOM_SELL, ExitType.EXIT_SIGNAL): logger.debug(f"{trade.pair} - Sell signal received. " f"exit_type=ExitType.{sell_signal.name}" + (f", custom_reason={custom_reason}" if custom_reason else "")) diff --git a/tests/edge/test_edge.py b/tests/edge/test_edge.py index 76005c734..4554a80a0 100644 --- a/tests/edge/test_edge.py +++ b/tests/edge/test_edge.py @@ -95,8 +95,8 @@ tc1 = BTContainer(data=[ [6, 5000, 5025, 4975, 4987, 6172, 0, 0], # should sell ], stop_loss=-0.99, roi={"0": float('inf')}, profit_perc=0.00, - trades=[BTrade(exit_reason=ExitType.SELL_SIGNAL, open_tick=1, close_tick=2), - BTrade(exit_reason=ExitType.SELL_SIGNAL, open_tick=4, close_tick=6)] + trades=[BTrade(exit_reason=ExitType.EXIT_SIGNAL, open_tick=1, close_tick=2), + BTrade(exit_reason=ExitType.EXIT_SIGNAL, open_tick=4, close_tick=6)] ) # 3) Entered, sl 1%, candle drops 8% => Trade closed, 1% loss diff --git a/tests/optimize/test_backtest_detail.py b/tests/optimize/test_backtest_detail.py index a942a4f73..5ea54acca 100644 --- a/tests/optimize/test_backtest_detail.py +++ b/tests/optimize/test_backtest_detail.py @@ -22,7 +22,7 @@ tc0 = BTContainer(data=[ [4, 5010, 5011, 4977, 4995, 6172, 0, 0], [5, 4995, 4995, 4950, 4950, 6172, 0, 0]], stop_loss=-0.01, roi={"0": 1}, profit_perc=0.002, use_exit_signal=True, - trades=[BTrade(exit_reason=ExitType.SELL_SIGNAL, open_tick=1, close_tick=4)] + trades=[BTrade(exit_reason=ExitType.EXIT_SIGNAL, open_tick=1, close_tick=4)] ) # Test 1: Stop-Loss Triggered 1% loss @@ -406,7 +406,7 @@ tc25 = BTContainer(data=[ [4, 5010, 5010, 4855, 4995, 6172, 0, 0], # Triggers stoploss + sellsignal acted on [5, 4995, 4995, 4950, 4950, 6172, 0, 0]], stop_loss=-0.01, roi={"0": 1}, profit_perc=0.002, use_exit_signal=True, - trades=[BTrade(exit_reason=ExitType.SELL_SIGNAL, open_tick=1, close_tick=4)] + trades=[BTrade(exit_reason=ExitType.EXIT_SIGNAL, open_tick=1, close_tick=4)] ) # Test 26: Sell with signal sell in candle 3 (ROI at signal candle) @@ -435,7 +435,7 @@ tc27 = BTContainer(data=[ [4, 5010, 5251, 4855, 4995, 6172, 0, 0], # Triggers ROI, sell-signal acted on [5, 4995, 4995, 4950, 4950, 6172, 0, 0]], stop_loss=-0.10, roi={"0": 0.05}, profit_perc=0.002, use_exit_signal=True, - trades=[BTrade(exit_reason=ExitType.SELL_SIGNAL, open_tick=1, close_tick=4)] + trades=[BTrade(exit_reason=ExitType.EXIT_SIGNAL, open_tick=1, close_tick=4)] ) # Test 28: trailing_stop should raise so candle 3 causes a stoploss @@ -548,7 +548,7 @@ tc34 = BTContainer(data=[ [5, 4995, 4995, 4950, 4950, 6172, 0, 0]], stop_loss=-0.01, roi={"0": 1}, profit_perc=0.002 * 5.0, use_exit_signal=True, leverage=5.0, - trades=[BTrade(exit_reason=ExitType.SELL_SIGNAL, open_tick=1, close_tick=4)] + trades=[BTrade(exit_reason=ExitType.EXIT_SIGNAL, open_tick=1, close_tick=4)] ) TESTS = [ diff --git a/tests/plugins/test_protections.py b/tests/plugins/test_protections.py index 370810c32..a72e8fbed 100644 --- a/tests/plugins/test_protections.py +++ b/tests/plugins/test_protections.py @@ -11,7 +11,7 @@ from tests.conftest import get_patched_freqtradebot, log_has_re def generate_mock_trade(pair: str, fee: float, is_open: bool, - exit_reason: str = ExitType.SELL_SIGNAL, + exit_reason: str = ExitType.EXIT_SIGNAL, min_ago_open: int = None, min_ago_close: int = None, profit_rate: float = 0.9 ): diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index 2cb66c0bd..07beac7f6 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -2135,7 +2135,7 @@ def test_handle_trade_use_exit_signal( else: patch_get_signal(freqtrade, enter_long=False, exit_long=True) assert freqtrade.handle_trade(trade) - assert log_has("ETH/USDT - Sell signal received. exit_type=ExitType.SELL_SIGNAL", + assert log_has("ETH/USDT - Sell signal received. exit_type=ExitType.EXIT_SIGNAL", caplog) @@ -3003,7 +3003,7 @@ def test_execute_trade_exit_custom_exit_price( freqtrade.execute_trade_exit( trade=trade, limit=ticker_usdt_sell_up()['ask' if is_short else 'bid'], - exit_reason=SellCheckTuple(exit_type=ExitType.SELL_SIGNAL) + exit_reason=SellCheckTuple(exit_type=ExitType.EXIT_SIGNAL) ) # Sell price must be different to default bid price @@ -3031,7 +3031,7 @@ def test_execute_trade_exit_custom_exit_price( 'profit_ratio': profit_ratio, 'stake_currency': 'USDT', 'fiat_currency': 'USD', - 'exit_reason': ExitType.SELL_SIGNAL.value, + 'exit_reason': ExitType.EXIT_SIGNAL.value, 'open_date': ANY, 'close_date': ANY, 'close_rate': ANY, @@ -3403,18 +3403,18 @@ def test_execute_trade_exit_insufficient_funds_error(default_conf_usdt, ticker_u @pytest.mark.parametrize('profit_only,bid,ask,handle_first,handle_second,exit_type,is_short', [ # Enable profit - (True, 2.18, 2.2, False, True, ExitType.SELL_SIGNAL.value, False), - (True, 2.18, 2.2, False, True, ExitType.SELL_SIGNAL.value, True), + (True, 2.18, 2.2, False, True, ExitType.EXIT_SIGNAL.value, False), + (True, 2.18, 2.2, False, True, ExitType.EXIT_SIGNAL.value, True), # # Disable profit - (False, 3.19, 3.2, True, False, ExitType.SELL_SIGNAL.value, False), - (False, 3.19, 3.2, True, False, ExitType.SELL_SIGNAL.value, True), + (False, 3.19, 3.2, True, False, ExitType.EXIT_SIGNAL.value, False), + (False, 3.19, 3.2, True, False, ExitType.EXIT_SIGNAL.value, True), # # Enable loss # # * Shouldn't this be ExitType.STOP_LOSS.value (True, 0.21, 0.22, False, False, None, False), (True, 2.41, 2.42, False, False, None, True), # Disable loss - (False, 0.10, 0.22, True, False, ExitType.SELL_SIGNAL.value, False), - (False, 0.10, 0.22, True, False, ExitType.SELL_SIGNAL.value, True), + (False, 0.10, 0.22, True, False, ExitType.EXIT_SIGNAL.value, False), + (False, 0.10, 0.22, True, False, ExitType.EXIT_SIGNAL.value, True), ]) def test_sell_profit_only( default_conf_usdt, limit_order, limit_order_open, is_short, @@ -3441,7 +3441,7 @@ def test_sell_profit_only( }) freqtrade = FreqtradeBot(default_conf_usdt) patch_get_signal(freqtrade, enter_short=is_short, enter_long=not is_short) - if exit_type == ExitType.SELL_SIGNAL.value: + if exit_type == ExitType.EXIT_SIGNAL.value: freqtrade.strategy.min_roi_reached = MagicMock(return_value=False) else: freqtrade.strategy.stop_loss_reached = MagicMock(return_value=SellCheckTuple( diff --git a/tests/test_integration.py b/tests/test_integration.py index b876fa067..ba57a9cfb 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -53,7 +53,7 @@ def test_may_execute_exit_stoploss_on_exchange_multi(default_conf, ticker, fee, # Sell 3rd trade (not called for the first trade) should_sell_mock = MagicMock(side_effect=[ SellCheckTuple(exit_type=ExitType.NONE), - SellCheckTuple(exit_type=ExitType.SELL_SIGNAL)] + SellCheckTuple(exit_type=ExitType.EXIT_SIGNAL)] ) cancel_order_mock = MagicMock() mocker.patch('freqtrade.exchange.Binance.stoploss', stoploss) @@ -119,7 +119,7 @@ def test_may_execute_exit_stoploss_on_exchange_multi(default_conf, ticker, fee, assert trade.is_open trade = trades[2] - assert trade.exit_reason == ExitType.SELL_SIGNAL.value + assert trade.exit_reason == ExitType.EXIT_SIGNAL.value assert not trade.is_open @@ -158,7 +158,7 @@ def test_forcebuy_last_unlimited(default_conf, ticker, fee, limit_buy_order, moc ) should_sell_mock = MagicMock(side_effect=[ SellCheckTuple(exit_type=ExitType.NONE), - SellCheckTuple(exit_type=ExitType.SELL_SIGNAL), + SellCheckTuple(exit_type=ExitType.EXIT_SIGNAL), SellCheckTuple(exit_type=ExitType.NONE), SellCheckTuple(exit_type=ExitType.NONE), SellCheckTuple(exit_type=ExitType.NONE)]