From d35d3bb38cf9de50b0d6d2a234297d6c8b892cee Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 1 Sep 2018 19:52:40 +0200 Subject: [PATCH] rename ta_on_candle to process_only_new_candles be more expressive --- docs/configuration.md | 2 +- freqtrade/constants.py | 2 +- freqtrade/strategy/interface.py | 6 +++--- freqtrade/strategy/resolver.py | 10 +++++----- freqtrade/tests/strategy/test_interface.py | 6 +++--- freqtrade/tests/strategy/test_strategy.py | 9 +++++---- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 64e75c51e..1d5fc0922 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -23,7 +23,7 @@ The table below will list all configuration parameters. | `ticker_interval` | [1m, 5m, 30m, 1h, 1d] | No | The ticker interval to use (1min, 5 min, 30 min, 1 hour or 1 day). Default is 5 minutes | `fiat_display_currency` | USD | Yes | Fiat currency used to show your profits. More information below. | `dry_run` | true | Yes | Define if the bot must be in Dry-run or production mode. -| `ta_on_candle` | false | No | If set to true indicators are processed only once a new candle arrives. If false each loop populates the indicators, this will mean the same candle is processed many times creating system load but can be useful of your strategy depends on tick data not only candle. Can be set either in Configuration or in the strategy. +| `process_only_new_candles` | false | No | If set to true indicators are processed only once a new candle arrives. If false each loop populates the indicators, this will mean the same candle is processed many times creating system load but can be useful of your strategy depends on tick data not only candle. Can be set either in Configuration or in the strategy. | `minimal_roi` | See below | No | Set the threshold in percent the bot will use to sell a trade. More information below. If set, this parameter will override `minimal_roi` from your strategy file. | `stoploss` | -0.10 | No | Value of the stoploss in percent used by the bot. More information below. If set, this parameter will override `stoploss` from your strategy file. | `trailing_stoploss` | false | No | Enables trailing stop-loss (based on `stoploss` in either configuration or strategy file). diff --git a/freqtrade/constants.py b/freqtrade/constants.py index 189b78617..92b090432 100644 --- a/freqtrade/constants.py +++ b/freqtrade/constants.py @@ -53,7 +53,7 @@ CONF_SCHEMA = { }, 'fiat_display_currency': {'type': 'string', 'enum': SUPPORTED_FIAT}, 'dry_run': {'type': 'boolean'}, - 'ta_on_candle': {'type': 'boolean'}, + 'process_only_new_candles': {'type': 'boolean'}, 'minimal_roi': { 'type': 'object', 'patternProperties': { diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index a9838a5cb..05ede129e 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -71,7 +71,7 @@ class IStrategy(ABC): ticker_interval: str # run "populate_indicators" only for new candle - ta_on_candle: bool = False + process_only_new_candles: bool = False # Dict to determine if analysis is necessary _last_candle_seen_per_pair: Dict[str, datetime] = {} @@ -124,8 +124,8 @@ class IStrategy(ABC): pair = str(metadata.get('pair')) - # always run if ta_on_candle is set to true - if (not self.ta_on_candle or + # always run if process_only_new_candles is set to true + if (not self.process_only_new_candles or self._last_candle_seen_per_pair.get(pair, None) != dataframe.iloc[-1]['date']): # Defs that only make change on new candle data. logging.debug("TA Analysis Launched") diff --git a/freqtrade/strategy/resolver.py b/freqtrade/strategy/resolver.py index 75fb99d69..35aee8d20 100644 --- a/freqtrade/strategy/resolver.py +++ b/freqtrade/strategy/resolver.py @@ -65,14 +65,14 @@ class StrategyResolver(object): else: config['ticker_interval'] = self.strategy.ticker_interval - if 'ta_on_candle' in config: - self.strategy.ta_on_candle = config['ta_on_candle'] + if 'process_only_new_candles' in config: + self.strategy.process_only_new_candles = config['process_only_new_candles'] logger.info( - "Override ta_on_candle 'ta_on_candle' with value in config file: %s.", - config['ta_on_candle'] + "Override process_only_new_candles 'process_only_new_candles' " + "with value in config file: %s.", config['process_only_new_candles'] ) else: - config['ta_on_candle'] = self.strategy.ta_on_candle + config['process_only_new_candles'] = self.strategy.process_only_new_candles # Sort and apply type conversions self.strategy.minimal_roi = OrderedDict(sorted( diff --git a/freqtrade/tests/strategy/test_interface.py b/freqtrade/tests/strategy/test_interface.py index e96dfb024..5afffd87f 100644 --- a/freqtrade/tests/strategy/test_interface.py +++ b/freqtrade/tests/strategy/test_interface.py @@ -131,7 +131,7 @@ def test_analyze_ticker_default(ticker_history, mocker, caplog) -> None: caplog.clear() strategy.analyze_ticker(ticker_history, {'pair': 'ETH/BTC'}) - # No analysis happens as ta_on_candle is true + # No analysis happens as process_only_new_candles is true assert ind_mock.call_count == 2 assert buy_mock.call_count == 2 assert buy_mock.call_count == 2 @@ -153,7 +153,7 @@ def test_analyze_ticker_skip_analyze(ticker_history, mocker, caplog) -> None: ) strategy = DefaultStrategy({}) - strategy.ta_on_candle = True + strategy.process_only_new_candles = True ret = strategy.analyze_ticker(ticker_history, {'pair': 'ETH/BTC'}) assert ind_mock.call_count == 1 @@ -165,7 +165,7 @@ def test_analyze_ticker_skip_analyze(ticker_history, mocker, caplog) -> None: caplog.clear() ret = strategy.analyze_ticker(ticker_history, {'pair': 'ETH/BTC'}) - # No analysis happens as ta_on_candle is true + # No analysis happens as process_only_new_candles is true assert ind_mock.call_count == 1 assert buy_mock.call_count == 1 assert buy_mock.call_count == 1 diff --git a/freqtrade/tests/strategy/test_strategy.py b/freqtrade/tests/strategy/test_strategy.py index 14b1ef1bd..8a6e7e617 100644 --- a/freqtrade/tests/strategy/test_strategy.py +++ b/freqtrade/tests/strategy/test_strategy.py @@ -165,19 +165,20 @@ def test_strategy_override_ticker_interval(caplog): ) in caplog.record_tuples -def test_strategy_override_ta_on_candle(caplog): +def test_strategy_override_process_only_new_candles(caplog): caplog.set_level(logging.INFO) config = { 'strategy': 'DefaultStrategy', - 'ta_on_candle': True + 'process_only_new_candles': True } resolver = StrategyResolver(config) - assert resolver.strategy.ta_on_candle + assert resolver.strategy.process_only_new_candles assert ('freqtrade.strategy.resolver', logging.INFO, - "Override ta_on_candle 'ta_on_candle' with value in config file: True." + "Override process_only_new_candles 'process_only_new_candles' " + "with value in config file: True." ) in caplog.record_tuples