Add ticker_interval support in strategy class

This commit is contained in:
Gerald Lonlas 2018-01-20 14:40:41 -08:00
parent 5eb7aa07a1
commit 41aa8f18fb
7 changed files with 41 additions and 4 deletions

View File

@ -383,7 +383,6 @@ CONF_SCHEMA = {
], ],
'required': [ 'required': [
'max_open_trades', 'max_open_trades',
'ticker_interval',
'stake_currency', 'stake_currency',
'stake_amount', 'stake_amount',
'fiat_display_currency', 'fiat_display_currency',

View File

@ -27,6 +27,9 @@ class DefaultStrategy(IStrategy):
# Optimal stoploss designed for the strategy # Optimal stoploss designed for the strategy
stoploss = -0.10 stoploss = -0.10
# Optimal ticker interval for the strategy
ticker_interval = 5
def populate_indicators(self, dataframe: DataFrame) -> DataFrame: def populate_indicators(self, dataframe: DataFrame) -> DataFrame:
""" """
Adds several different TA indicators to the given DataFrame Adds several different TA indicators to the given DataFrame

View File

@ -15,7 +15,8 @@ class IStrategy(ABC):
""" """
Attributes you can use: Attributes you can use:
minimal_roi -> Dict: Minimal ROI designed for the strategy minimal_roi -> Dict: Minimal ROI designed for the strategy
stoploss -> float: ptimal stoploss designed for the strategy stoploss -> float: optimal stoploss designed for the strategy
ticker_interval -> int: value of the ticker interval to use for the strategy
""" """
@abstractmethod @abstractmethod

View File

@ -41,10 +41,23 @@ class Strategy(object):
if 'stoploss' in config: if 'stoploss' in config:
self.custom_strategy.stoploss = config['stoploss'] self.custom_strategy.stoploss = config['stoploss']
self.logger.info("Override strategy \'stoploss\' with value in config file.") self.logger.info(
"Override strategy \'stoploss\' with value in config file: {}.".format(
config['stoploss']
)
)
if 'ticker_interval' in config:
self.custom_strategy.ticker_interval = config['ticker_interval']
self.logger.info(
"Override strategy \'ticker_interval\' with value in config file: {}.".format(
config['ticker_interval']
)
)
self.minimal_roi = self.custom_strategy.minimal_roi self.minimal_roi = self.custom_strategy.minimal_roi
self.stoploss = self.custom_strategy.stoploss self.stoploss = self.custom_strategy.stoploss
self.ticker_interval = self.custom_strategy.ticker_interval
def _load_strategy(self, strategy_name: str) -> None: def _load_strategy(self, strategy_name: str) -> None:
""" """

View File

@ -18,6 +18,7 @@ def test_default_strategy_class_name():
def test_default_strategy_structure(): def test_default_strategy_structure():
assert hasattr(DefaultStrategy, 'minimal_roi') assert hasattr(DefaultStrategy, 'minimal_roi')
assert hasattr(DefaultStrategy, 'stoploss') assert hasattr(DefaultStrategy, 'stoploss')
assert hasattr(DefaultStrategy, 'ticker_interval')
assert hasattr(DefaultStrategy, 'populate_indicators') assert hasattr(DefaultStrategy, 'populate_indicators')
assert hasattr(DefaultStrategy, 'populate_buy_trend') assert hasattr(DefaultStrategy, 'populate_buy_trend')
assert hasattr(DefaultStrategy, 'populate_sell_trend') assert hasattr(DefaultStrategy, 'populate_sell_trend')
@ -30,6 +31,7 @@ def test_default_strategy(result):
assert type(strategy.minimal_roi) is dict assert type(strategy.minimal_roi) is dict
assert type(strategy.stoploss) is float assert type(strategy.stoploss) is float
assert type(strategy.ticker_interval) is int
indicators = strategy.populate_indicators(result) indicators = strategy.populate_indicators(result)
assert type(indicators) is DataFrame assert type(indicators) is DataFrame
assert type(strategy.populate_buy_trend(indicators)) is DataFrame assert type(strategy.populate_buy_trend(indicators)) is DataFrame

View File

@ -108,7 +108,23 @@ def test_strategy_override_stoploss(caplog):
assert strategy.stoploss == -0.5 assert strategy.stoploss == -0.5
assert ('freqtrade.strategy.strategy', assert ('freqtrade.strategy.strategy',
logging.INFO, logging.INFO,
'Override strategy \'stoploss\' with value in config file.' 'Override strategy \'stoploss\' with value in config file: -0.5.'
) in caplog.record_tuples
def test_strategy_override_ticker_interval(caplog):
config = {
'strategy': 'default_strategy',
'ticker_interval': 60
}
strategy = Strategy()
strategy.init(config)
assert hasattr(strategy.custom_strategy, 'ticker_interval')
assert strategy.ticker_interval == 60
assert ('freqtrade.strategy.strategy',
logging.INFO,
'Override strategy \'ticker_interval\' with value in config file: 60.'
) in caplog.record_tuples ) in caplog.record_tuples

View File

@ -47,6 +47,9 @@ class TestStrategy(IStrategy):
# This attribute will be overridden if the config file contains "stoploss" # This attribute will be overridden if the config file contains "stoploss"
stoploss = -0.10 stoploss = -0.10
# Optimal ticker interval for the strategy
ticker_interval = 5
def populate_indicators(self, dataframe: DataFrame) -> DataFrame: def populate_indicators(self, dataframe: DataFrame) -> DataFrame:
""" """
Adds several different TA indicators to the given DataFrame Adds several different TA indicators to the given DataFrame