Allow control from strategy

This commit is contained in:
Matthias 2018-08-09 19:24:00 +02:00
parent 029d61b8c5
commit c4e43039f2
3 changed files with 17 additions and 1 deletions

View File

@ -70,6 +70,9 @@ class IStrategy(ABC):
# associated ticker interval # associated ticker interval
ticker_interval: str ticker_interval: str
# run "populate_indicators" only for new candle
ta_on_candle: bool = False
# Dict to determine if analysis is necessary # Dict to determine if analysis is necessary
candle_seen: Dict[str, datetime] = {} candle_seen: Dict[str, datetime] = {}
@ -121,7 +124,8 @@ class IStrategy(ABC):
pair = str(metadata.get('pair')) pair = str(metadata.get('pair'))
if (not self.config.get('ta_on_candle') or # always run if ta_on_candle is set to true
if (not self.ta_on_candle or
self.candle_seen.get(pair, None) != dataframe.iloc[-1]['date']): self.candle_seen.get(pair, None) != dataframe.iloc[-1]['date']):
# Defs that only make change on new candle data. # Defs that only make change on new candle data.
logging.debug("TA Analysis Launched") logging.debug("TA Analysis Launched")

View File

@ -65,6 +65,15 @@ class StrategyResolver(object):
else: else:
config['ticker_interval'] = self.strategy.ticker_interval config['ticker_interval'] = self.strategy.ticker_interval
if 'ta_on_candle' in config:
self.strategy.ta_on_candle = config['ta_on_candle']
logger.info(
"Override ta_on_candle \'ta_on_candle\' with value in config file: %s.",
config['ta_on_candle']
)
else:
config['ta_on_candle'] = self.strategy.ta_on_candle
# Sort and apply type conversions # Sort and apply type conversions
self.strategy.minimal_roi = OrderedDict(sorted( self.strategy.minimal_roi = OrderedDict(sorted(
{int(key): value for (key, value) in self.strategy.minimal_roi.items()}.items(), {int(key): value for (key, value) in self.strategy.minimal_roi.items()}.items(),

View File

@ -45,6 +45,9 @@ class TestStrategy(IStrategy):
# Optimal ticker interval for the strategy # Optimal ticker interval for the strategy
ticker_interval = '5m' ticker_interval = '5m'
# run "populate_indicators" only for new candle
ta_on_candle = False
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
""" """
Adds several different TA indicators to the given DataFrame Adds several different TA indicators to the given DataFrame