apply __slots__ to resolver and reintroduce type conversations
This commit is contained in:
		| @@ -21,6 +21,9 @@ class StrategyResolver(object): | |||||||
|     """ |     """ | ||||||
|     This class contains all the logic to load custom strategy class |     This class contains all the logic to load custom strategy class | ||||||
|     """ |     """ | ||||||
|  |  | ||||||
|  |     __slots__ = ['strategy'] | ||||||
|  |  | ||||||
|     def __init__(self, config: Optional[Dict] = None) -> None: |     def __init__(self, config: Optional[Dict] = None) -> None: | ||||||
|         """ |         """ | ||||||
|         Load the custom class from config parameter |         Load the custom class from config parameter | ||||||
| @@ -39,22 +42,24 @@ class StrategyResolver(object): | |||||||
|             logger.info("Override strategy \'minimal_roi\' with value in config file.") |             logger.info("Override strategy \'minimal_roi\' with value in config file.") | ||||||
|  |  | ||||||
|         if 'stoploss' in config: |         if 'stoploss' in config: | ||||||
|             self.strategy.stoploss = float(config['stoploss']) |             self.strategy.stoploss = config['stoploss'] | ||||||
|             logger.info( |             logger.info( | ||||||
|                 "Override strategy \'stoploss\' with value in config file: %s.", config['stoploss'] |                 "Override strategy \'stoploss\' with value in config file: %s.", config['stoploss'] | ||||||
|             ) |             ) | ||||||
|  |  | ||||||
|         if 'ticker_interval' in config: |         if 'ticker_interval' in config: | ||||||
|             self.strategy.ticker_interval = int(config['ticker_interval']) |             self.strategy.ticker_interval = config['ticker_interval'] | ||||||
|             logger.info( |             logger.info( | ||||||
|                 "Override strategy \'ticker_interval\' with value in config file: %s.", |                 "Override strategy \'ticker_interval\' with value in config file: %s.", | ||||||
|                 config['ticker_interval'] |                 config['ticker_interval'] | ||||||
|             ) |             ) | ||||||
|  |  | ||||||
|         # Minimal ROI designed for the strategy |         # 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(), | ||||||
|             key=lambda t: t[0]))  # sort after converting to number |             key=lambda t: t[0])) | ||||||
|  |         self.strategy.stoploss = float(self.strategy.stoploss) | ||||||
|  |         self.strategy.ticker_interval = int(self.strategy.ticker_interval) | ||||||
|  |  | ||||||
|     def _load_strategy(self, strategy_name: str) -> Optional[IStrategy]: |     def _load_strategy(self, strategy_name: str) -> Optional[IStrategy]: | ||||||
|         """ |         """ | ||||||
| @@ -76,16 +81,12 @@ class StrategyResolver(object): | |||||||
|  |  | ||||||
|             raise ImportError('not found') |             raise ImportError('not found') | ||||||
|         # Fallback to the default strategy |         # Fallback to the default strategy | ||||||
|         except (ImportError, TypeError) as error: |         except (ImportError, TypeError): | ||||||
|             logger.error( |             logger.exception( | ||||||
|                 "Impossible to load Strategy '%s'. This class does not exist" |                 "Impossible to load Strategy '%s'. This class does not exist" | ||||||
|                 " or contains Python code errors", |                 " or contains Python code errors", | ||||||
|                 strategy_name |                 strategy_name | ||||||
|             ) |             ) | ||||||
|             logger.error( |  | ||||||
|                 "The error is:\n%s.", |  | ||||||
|                 error |  | ||||||
|             ) |  | ||||||
|             return None |             return None | ||||||
|  |  | ||||||
|     @staticmethod |     @staticmethod | ||||||
|   | |||||||
| @@ -115,7 +115,6 @@ def test_strategy_override_ticker_interval(caplog): | |||||||
|  |  | ||||||
| def test_strategy_fallback_default_strategy(): | def test_strategy_fallback_default_strategy(): | ||||||
|     strategy = StrategyResolver() |     strategy = StrategyResolver() | ||||||
|     strategy.logger = logging.getLogger(__name__) |  | ||||||
|  |  | ||||||
|     assert not hasattr(StrategyResolver, 'custom_strategy') |     assert not hasattr(StrategyResolver, 'custom_strategy') | ||||||
|     strategy._load_strategy('../../super_duper') |     strategy._load_strategy('../../super_duper') | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user