From 95cbbf1cb5e1baa9b7657b631fa4c29c9e50a987 Mon Sep 17 00:00:00 2001 From: misagh Date: Wed, 14 Nov 2018 12:53:20 +0100 Subject: [PATCH] adding edge configuration to cli --- freqtrade/configuration.py | 42 ++++++++++++++++++++++++++++++++++++++ freqtrade/edge/__init__.py | 5 +++-- freqtrade/optimize/edge.py | 3 ++- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/freqtrade/configuration.py b/freqtrade/configuration.py index e043525a7..163581f84 100644 --- a/freqtrade/configuration.py +++ b/freqtrade/configuration.py @@ -58,6 +58,9 @@ class Configuration(object): # Load Backtesting config = self._load_backtesting_config(config) + # Load Edge + config = self._load_edge_config(config) + # Load Hyperopt config = self._load_hyperopt_config(config) @@ -213,6 +216,45 @@ class Configuration(object): return config + def _load_edge_config(self, config: Dict[str, Any]) -> Dict[str, Any]: + """ + Extract information for sys.argv and load Edge configuration + :return: configuration as dictionary + """ + + # If --timerange is used we add it to the configuration + if 'timerange' in self.args and self.args.timerange: + config.update({'timerange': self.args.timerange}) + logger.info('Parameter --timerange detected: %s ...', self.args.timerange) + + # If --datadir is used we add it to the configuration + if 'datadir' in self.args and self.args.datadir: + config.update({'datadir': self.args.datadir}) + else: + config.update({'datadir': self._create_default_datadir(config)}) + logger.info('Using data folder: %s ...', config.get('datadir')) + + # If -r/--refresh-pairs-cached is used we add it to the configuration + if 'refresh_pairs' in self.args and self.args.refresh_pairs: + config.update({'refresh_pairs': True}) + logger.info('Parameter -r/--refresh-pairs-cached detected ...') + + if 'ticker_interval' in self.args and self.args.ticker_interval: + config.update({'ticker_interval': self.args.ticker_interval}) + logger.info('Overriding ticker interval with Command line argument') + + # If --export is used we add it to the configuration + if 'export' in self.args and self.args.export: + config.update({'export': self.args.export}) + logger.info('Parameter --export detected: %s ...', self.args.export) + + # If --export-filename is used we add it to the configuration + if 'export' in config and 'exportfilename' in self.args and self.args.exportfilename: + config.update({'exportfilename': self.args.exportfilename}) + logger.info('Storing backtest results to %s ...', self.args.exportfilename) + + return config + def _load_hyperopt_config(self, config: Dict[str, Any]) -> Dict[str, Any]: """ Extract information for sys.argv and load Hyperopt configuration diff --git a/freqtrade/edge/__init__.py b/freqtrade/edge/__init__.py index bb1cd118f..55c59b644 100644 --- a/freqtrade/edge/__init__.py +++ b/freqtrade/edge/__init__.py @@ -35,7 +35,7 @@ class Edge(): 'pair_info', ['stoploss', 'winrate', 'risk_reward_ratio', 'required_risk_reward', 'expectancy']) - def __init__(self, config: Dict[str, Any], exchange, strategy, refresh_pairs=True) -> None: + def __init__(self, config: Dict[str, Any], exchange, strategy) -> None: self.config = config self.exchange = exchange @@ -53,6 +53,7 @@ class Edge(): self._allowed_risk: float = self.edge_config.get('allowed_risk') self._since_number_of_days: int = self.edge_config.get('calculate_since_number_of_days', 14) self._last_updated: int = 0 # Timestamp of pairs last updated time + self._refresh_pairs = True self._stoploss_range_min = float(self.edge_config.get('stoploss_range_min', -0.01)) self._stoploss_range_max = float(self.edge_config.get('stoploss_range_max', -0.05)) @@ -86,7 +87,7 @@ class Edge(): self.config['datadir'], pairs=pairs, ticker_interval=self.ticker_interval, - refresh_pairs=True, + refresh_pairs=self._refresh_pairs, exchange=self.exchange, timerange=self._timerange ) diff --git a/freqtrade/optimize/edge.py b/freqtrade/optimize/edge.py index 49c58987b..585c397fd 100644 --- a/freqtrade/optimize/edge.py +++ b/freqtrade/optimize/edge.py @@ -48,6 +48,7 @@ class EdgeCli(object): self.strategy = StrategyResolver(self.config).strategy self.edge = Edge(config, self.exchange, self.strategy) + self.edge._refresh_pairs = self.config.get('refresh_pairs', False) def start(self) -> None: self.edge.calculate() @@ -80,7 +81,7 @@ def start(args: Namespace) -> None: # Initialize configuration config = setup_configuration(args) logger.info('Starting freqtrade in Edge mode') - print('edge talking here...') + # Initialize Edge object edge_cli = EdgeCli(config) edge_cli.start()