strategy: remove unneeded population methods in resolver

This commit is contained in:
gcarq
2018-03-24 23:20:21 +01:00
parent 1cec06f808
commit 280886104c
3 changed files with 37 additions and 79 deletions

View File

@@ -10,8 +10,6 @@ import os
from collections import OrderedDict
from typing import Optional, Dict, Type
from pandas import DataFrame
from freqtrade.constants import Constants
from freqtrade.strategy.interface import IStrategy
@@ -38,42 +36,37 @@ class StrategyResolver(object):
strategy = Constants.DEFAULT_STRATEGY
# Try to load the strategy
self._load_strategy(strategy)
self.strategy = self._load_strategy(strategy)
# Set attributes
# Check if we need to override configuration
if 'minimal_roi' in config:
self.custom_strategy.minimal_roi = config['minimal_roi']
self.strategy.minimal_roi = config['minimal_roi']
logger.info("Override strategy \'minimal_roi\' with value in config file.")
if 'stoploss' in config:
self.custom_strategy.stoploss = config['stoploss']
self.strategy.stoploss = float(config['stoploss'])
logger.info(
"Override strategy \'stoploss\' with value in config file: %s.", config['stoploss']
)
if 'ticker_interval' in config:
self.custom_strategy.ticker_interval = config['ticker_interval']
self.strategy.ticker_interval = int(config['ticker_interval'])
logger.info(
"Override strategy \'ticker_interval\' with value in config file: %s.",
config['ticker_interval']
)
# Minimal ROI designed for the strategy
self.minimal_roi = OrderedDict(sorted(
{int(key): value for (key, value) in self.custom_strategy.minimal_roi.items()}.items(),
self.strategy.minimal_roi = OrderedDict(sorted(
{int(key): value for (key, value) in self.strategy.minimal_roi.items()}.items(),
key=lambda t: t[0])) # sort after converting to number
# Optimal stoploss designed for the strategy
self.stoploss = float(self.custom_strategy.stoploss)
self.ticker_interval = int(self.custom_strategy.ticker_interval)
def _load_strategy(self, strategy_name: str) -> None:
def _load_strategy(self, strategy_name: str) -> Optional[IStrategy]:
"""
Search and loads the specified strategy.
:param strategy_name: name of the module to import
:return: None
:return: Strategy instance or None
"""
try:
current_path = os.path.dirname(os.path.realpath(__file__))
@@ -82,10 +75,10 @@ class StrategyResolver(object):
current_path,
]
for path in abs_paths:
self.custom_strategy = self._search_strategy(path, strategy_name)
if self.custom_strategy:
strategy = self._search_strategy(path, strategy_name)
if strategy:
logger.info('Using resolved strategy %s from \'%s\'', strategy_name, path)
return None
return strategy
raise ImportError('not found')
# Fallback to the default strategy
@@ -99,6 +92,7 @@ class StrategyResolver(object):
"The error is:\n%s.",
error
)
return None
@staticmethod
def _get_valid_strategies(module_path: str, strategy_name: str) -> Optional[Type[IStrategy]]:
@@ -139,28 +133,3 @@ class StrategyResolver(object):
if strategy:
return strategy()
return None
def populate_indicators(self, dataframe: DataFrame) -> DataFrame:
"""
Populate indicators that will be used in the Buy and Sell strategy
:param dataframe: Raw data from the exchange and parsed by parse_ticker_dataframe()
:return: a Dataframe with all mandatory indicators for the strategies
"""
return self.custom_strategy.populate_indicators(dataframe)
def populate_buy_trend(self, dataframe: DataFrame) -> DataFrame:
"""
Based on TA indicators, populates the buy signal for the given dataframe
:param dataframe: DataFrame
:return: DataFrame with buy column
:return:
"""
return self.custom_strategy.populate_buy_trend(dataframe)
def populate_sell_trend(self, dataframe: DataFrame) -> DataFrame:
"""
Based on TA indicators, populates the sell signal for the given dataframe
:param dataframe: DataFrame
:return: DataFrame with buy column
"""
return self.custom_strategy.populate_sell_trend(dataframe)