From a07cf4596895dab91d798add2b8a5f534147d3cb Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Tue, 4 Jan 2022 23:14:05 -0600 Subject: [PATCH] sell_flag -> exit_flag --- freqtrade/freqtradebot.py | 2 +- freqtrade/optimize/backtesting.py | 2 +- freqtrade/strategy/interface.py | 4 ++-- tests/strategy/test_interface.py | 16 ++++++++-------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 1e9862b0a..3c0000b79 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -1039,7 +1039,7 @@ class FreqtradeBot(LoggingMixin): force_stoploss=self.edge.stoploss(trade.pair) if self.edge else 0 ) - if should_exit.sell_flag: + if should_exit.exit_flag: logger.info(f'Exit for {trade.pair} detected. Reason: {should_exit.exit_type}' f'Tag: {exit_tag if exit_tag is not None else "None"}') self.execute_trade_exit(trade, exit_rate, should_exit, exit_tag=exit_tag) diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index 81428c75f..688412044 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -388,7 +388,7 @@ class Backtesting: low=sell_row[LOW_IDX], high=sell_row[HIGH_IDX] ) - if sell.sell_flag: + if sell.exit_flag: trade.close_date = sell_candle_time trade_dur = int((trade.close_date_utc - trade.open_date_utc).total_seconds() // 60) diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index 0505a809e..06d5ff5d8 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -42,7 +42,7 @@ class ExitCheckTuple: self.exit_reason = exit_reason or exit_type.value @property - def sell_flag(self): + def exit_flag(self): return self.exit_type != ExitType.NONE @@ -825,7 +825,7 @@ class IStrategy(ABC, HyperStrategyMixin): logger.debug(f"{trade.pair} - Required profit reached. exit_type=ExitType.ROI") return ExitCheckTuple(exit_type=ExitType.ROI) - if stoplossflag.sell_flag: + if stoplossflag.exit_flag: logger.debug(f"{trade.pair} - Stoploss hit. exit_type={stoplossflag.exit_type}") return stoplossflag diff --git a/tests/strategy/test_interface.py b/tests/strategy/test_interface.py index 4214f7d2a..00276246f 100644 --- a/tests/strategy/test_interface.py +++ b/tests/strategy/test_interface.py @@ -442,9 +442,9 @@ def test_stop_loss_reached(default_conf, fee, profit, adjusted, expected, traili assert isinstance(sl_flag, ExitCheckTuple) assert sl_flag.exit_type == expected if expected == ExitType.NONE: - assert sl_flag.sell_flag is False + assert sl_flag.exit_flag is False else: - assert sl_flag.sell_flag is True + assert sl_flag.exit_flag is True assert round(trade.stop_loss, 2) == adjusted sl_flag = strategy.stop_loss_reached(current_rate=trade.open_rate * (1 + profit2), trade=trade, @@ -452,9 +452,9 @@ def test_stop_loss_reached(default_conf, fee, profit, adjusted, expected, traili force_stoploss=0, high=None) assert sl_flag.exit_type == expected2 if expected2 == ExitType.NONE: - assert sl_flag.sell_flag is False + assert sl_flag.exit_flag is False else: - assert sl_flag.sell_flag is True + assert sl_flag.exit_flag is True assert round(trade.stop_loss, 2) == adjusted2 strategy.custom_stoploss = original_stopvalue @@ -479,14 +479,14 @@ def test_custom_exit(default_conf, fee, caplog) -> None: enter=False, exit_=False, low=None, high=None) - assert res.sell_flag is False + assert res.exit_flag is False assert res.exit_type == ExitType.NONE strategy.custom_exit = MagicMock(return_value=True) res = strategy.should_exit(trade, 1, now, enter=False, exit_=False, low=None, high=None) - assert res.sell_flag is True + assert res.exit_flag is True assert res.exit_type == ExitType.CUSTOM_EXIT assert res.exit_reason == 'custom_exit' @@ -496,7 +496,7 @@ def test_custom_exit(default_conf, fee, caplog) -> None: enter=False, exit_=False, low=None, high=None) assert res.exit_type == ExitType.CUSTOM_EXIT - assert res.sell_flag is True + assert res.exit_flag is True assert res.exit_reason == 'hello world' caplog.clear() @@ -505,7 +505,7 @@ def test_custom_exit(default_conf, fee, caplog) -> None: enter=False, exit_=False, low=None, high=None) assert res.exit_type == ExitType.CUSTOM_EXIT - assert res.sell_flag is True + assert res.exit_flag is True assert res.exit_reason == 'h' * 64 assert log_has_re('Custom sell reason returned from custom_exit is too long.*', caplog)