Cleanup arguments and test_arguments
This commit is contained in:
		| @@ -354,8 +354,9 @@ ARGS_LIST_EXCHANGE = ["print_one_column"] | |||||||
| ARGS_DOWNLOADER = ARGS_COMMON + ["pairs", "pairs_file", "days", "exchange", "timeframes", "erase"] | ARGS_DOWNLOADER = ARGS_COMMON + ["pairs", "pairs_file", "days", "exchange", "timeframes", "erase"] | ||||||
|  |  | ||||||
| ARGS_PLOT_DATAFRAME = (ARGS_COMMON + ARGS_STRATEGY + | ARGS_PLOT_DATAFRAME = (ARGS_COMMON + ARGS_STRATEGY + | ||||||
|                        ["pairs", "indicators1", "indicators2", "plot_limit", "db_url", "trade_source", |                        ["pairs", "indicators1", "indicators2", "plot_limit", "db_url", | ||||||
|                         "export", "exportfilename", "timerange", "refresh_pairs", "live"]) |                         "trade_source", "export", "exportfilename", "timerange", | ||||||
|  |                         "refresh_pairs", "live"]) | ||||||
|  |  | ||||||
| ARGS_PLOT_PROFIT = (ARGS_COMMON + ARGS_STRATEGY + | ARGS_PLOT_PROFIT = (ARGS_COMMON + ARGS_STRATEGY + | ||||||
|                     ["pairs", "timerange", "export", "exportfilename"]) |                     ["pairs", "timerange", "export", "exportfilename"]) | ||||||
| @@ -419,244 +420,6 @@ class Arguments(object): | |||||||
|             opt = AVAILABLE_CLI_OPTIONS[val] |             opt = AVAILABLE_CLI_OPTIONS[val] | ||||||
|             parser.add_argument(*opt.cli, **opt.kwargs) |             parser.add_argument(*opt.cli, **opt.kwargs) | ||||||
|  |  | ||||||
|     def common_options(self) -> None: |  | ||||||
|         """ |  | ||||||
|         Parses arguments that are common for the main Freqtrade, all subcommands and scripts. |  | ||||||
|         """ |  | ||||||
|         parser = self.parser |  | ||||||
|  |  | ||||||
|         parser.add_argument( |  | ||||||
|             '-v', '--verbose', |  | ||||||
|             help='Verbose mode (-vv for more, -vvv to get all messages).', |  | ||||||
|             action='count', |  | ||||||
|             dest='loglevel', |  | ||||||
|             default=0, |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '--logfile', |  | ||||||
|             help='Log to the file specified.', |  | ||||||
|             dest='logfile', |  | ||||||
|             metavar='FILE', |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '--version', |  | ||||||
|             action='version', |  | ||||||
|             version=f'%(prog)s {__version__}' |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '-c', '--config', |  | ||||||
|             help=f'Specify configuration file (default: `{constants.DEFAULT_CONFIG}`). ' |  | ||||||
|                  f'Multiple --config options may be used. ' |  | ||||||
|                  f'Can be set to `-` to read config from stdin.', |  | ||||||
|             dest='config', |  | ||||||
|             action='append', |  | ||||||
|             metavar='PATH', |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '-d', '--datadir', |  | ||||||
|             help='Path to backtest data.', |  | ||||||
|             dest='datadir', |  | ||||||
|             metavar='PATH', |  | ||||||
|         ) |  | ||||||
|  |  | ||||||
|     def common_optimize_options(self, subparser: argparse.ArgumentParser = None) -> None: |  | ||||||
|         """ |  | ||||||
|         Parses arguments common for Backtesting, Edge and Hyperopt modules. |  | ||||||
|         :param parser: |  | ||||||
|         """ |  | ||||||
|         parser = subparser or self.parser |  | ||||||
|  |  | ||||||
|         parser.add_argument( |  | ||||||
|             '-i', '--ticker-interval', |  | ||||||
|             help='Specify ticker interval (`1m`, `5m`, `30m`, `1h`, `1d`).', |  | ||||||
|             dest='ticker_interval', |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '--timerange', |  | ||||||
|             help='Specify what timerange of data to use.', |  | ||||||
|             dest='timerange', |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '--max_open_trades', |  | ||||||
|             help='Specify max_open_trades to use.', |  | ||||||
|             type=int, |  | ||||||
|             dest='max_open_trades', |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '--stake_amount', |  | ||||||
|             help='Specify stake_amount.', |  | ||||||
|             type=float, |  | ||||||
|             dest='stake_amount', |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '-r', '--refresh-pairs-cached', |  | ||||||
|             help='Refresh the pairs files in tests/testdata with the latest data from the ' |  | ||||||
|                  'exchange. Use it if you want to run your optimization commands with ' |  | ||||||
|                  'up-to-date data.', |  | ||||||
|             action='store_true', |  | ||||||
|             dest='refresh_pairs', |  | ||||||
|         ) |  | ||||||
|  |  | ||||||
|     def backtesting_options(self, subparser: argparse.ArgumentParser = None) -> None: |  | ||||||
|         """ |  | ||||||
|         Parses given arguments for Backtesting module. |  | ||||||
|         """ |  | ||||||
|         parser = subparser or self.parser |  | ||||||
|  |  | ||||||
|         parser.add_argument( |  | ||||||
|             '--eps', '--enable-position-stacking', |  | ||||||
|             help='Allow buying the same pair multiple times (position stacking).', |  | ||||||
|             action='store_true', |  | ||||||
|             dest='position_stacking', |  | ||||||
|             default=False |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '--dmmp', '--disable-max-market-positions', |  | ||||||
|             help='Disable applying `max_open_trades` during backtest ' |  | ||||||
|                  '(same as setting `max_open_trades` to a very high number).', |  | ||||||
|             action='store_false', |  | ||||||
|             dest='use_max_market_positions', |  | ||||||
|             default=True |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '-l', '--live', |  | ||||||
|             help='Use live data.', |  | ||||||
|             action='store_true', |  | ||||||
|             dest='live', |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '--strategy-list', |  | ||||||
|             help='Provide a comma-separated list of strategies to backtest. ' |  | ||||||
|                  'Please note that ticker-interval needs to be set either in config ' |  | ||||||
|                  'or via command line. When using this together with `--export trades`, ' |  | ||||||
|                  'the strategy-name is injected into the filename ' |  | ||||||
|                  '(so `backtest-data.json` becomes `backtest-data-DefaultStrategy.json`', |  | ||||||
|             nargs='+', |  | ||||||
|             dest='strategy_list', |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '--export', |  | ||||||
|             help='Export backtest results, argument are: trades. ' |  | ||||||
|                  'Example: `--export=trades`', |  | ||||||
|             dest='export', |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '--export-filename', |  | ||||||
|             help='Save backtest results to the file with this filename (default: `%(default)s`). ' |  | ||||||
|                  'Requires `--export` to be set as well. ' |  | ||||||
|                  'Example: `--export-filename=user_data/backtest_data/backtest_today.json`', |  | ||||||
|             default=os.path.join('user_data', 'backtest_data', 'backtest-result.json'), |  | ||||||
|             dest='exportfilename', |  | ||||||
|             metavar='PATH', |  | ||||||
|         ) |  | ||||||
|  |  | ||||||
|     def edge_options(self, subparser: argparse.ArgumentParser = None) -> None: |  | ||||||
|         """ |  | ||||||
|         Parses given arguments for Edge module. |  | ||||||
|         """ |  | ||||||
|         parser = subparser or self.parser |  | ||||||
|  |  | ||||||
|         parser.add_argument( |  | ||||||
|             '--stoplosses', |  | ||||||
|             help='Defines a range of stoploss values against which edge will assess the strategy. ' |  | ||||||
|                  'The format is "min,max,step" (without any space). ' |  | ||||||
|                  'Example: `--stoplosses=-0.01,-0.1,-0.001`', |  | ||||||
|             dest='stoploss_range', |  | ||||||
|         ) |  | ||||||
|  |  | ||||||
|     def hyperopt_options(self, subparser: argparse.ArgumentParser = None) -> None: |  | ||||||
|         """ |  | ||||||
|         Parses given arguments for Hyperopt module. |  | ||||||
|         """ |  | ||||||
|         parser = subparser or self.parser |  | ||||||
|  |  | ||||||
|         parser.add_argument( |  | ||||||
|             '--customhyperopt', |  | ||||||
|             help='Specify hyperopt class name (default: `%(default)s`).', |  | ||||||
|             dest='hyperopt', |  | ||||||
|             default=constants.DEFAULT_HYPEROPT, |  | ||||||
|             metavar='NAME', |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '--eps', '--enable-position-stacking', |  | ||||||
|             help='Allow buying the same pair multiple times (position stacking).', |  | ||||||
|             action='store_true', |  | ||||||
|             dest='position_stacking', |  | ||||||
|             default=False |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '--dmmp', '--disable-max-market-positions', |  | ||||||
|             help='Disable applying `max_open_trades` during backtest ' |  | ||||||
|                  '(same as setting `max_open_trades` to a very high number).', |  | ||||||
|             action='store_false', |  | ||||||
|             dest='use_max_market_positions', |  | ||||||
|             default=True |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '-e', '--epochs', |  | ||||||
|             help='Specify number of epochs (default: %(default)d).', |  | ||||||
|             dest='epochs', |  | ||||||
|             default=constants.HYPEROPT_EPOCH, |  | ||||||
|             type=int, |  | ||||||
|             metavar='INT', |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '-s', '--spaces', |  | ||||||
|             help='Specify which parameters to hyperopt. Space-separated list. ' |  | ||||||
|                  'Default: `%(default)s`.', |  | ||||||
|             choices=['all', 'buy', 'sell', 'roi', 'stoploss'], |  | ||||||
|             default='all', |  | ||||||
|             nargs='+', |  | ||||||
|             dest='spaces', |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '--print-all', |  | ||||||
|             help='Print all results, not only the best ones.', |  | ||||||
|             action='store_true', |  | ||||||
|             dest='print_all', |  | ||||||
|             default=False |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '-j', '--job-workers', |  | ||||||
|             help='The number of concurrently running jobs for hyperoptimization ' |  | ||||||
|                  '(hyperopt worker processes). ' |  | ||||||
|                  'If -1 (default), all CPUs are used, for -2, all CPUs but one are used, etc. ' |  | ||||||
|                  'If 1 is given, no parallel computing code is used at all.', |  | ||||||
|             dest='hyperopt_jobs', |  | ||||||
|             default=-1, |  | ||||||
|             type=int, |  | ||||||
|             metavar='JOBS', |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '--random-state', |  | ||||||
|             help='Set random state to some positive integer for reproducible hyperopt results.', |  | ||||||
|             dest='hyperopt_random_state', |  | ||||||
|             type=check_int_positive, |  | ||||||
|             metavar='INT', |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '--min-trades', |  | ||||||
|             help="Set minimal desired number of trades for evaluations in the hyperopt " |  | ||||||
|                  "optimization path (default: 1).", |  | ||||||
|             dest='hyperopt_min_trades', |  | ||||||
|             default=1, |  | ||||||
|             type=check_int_positive, |  | ||||||
|             metavar='INT', |  | ||||||
|         ) |  | ||||||
|  |  | ||||||
|     def list_exchanges_options(self, subparser: argparse.ArgumentParser = None) -> None: |  | ||||||
|         """ |  | ||||||
|         Parses given arguments for the list-exchanges command. |  | ||||||
|         """ |  | ||||||
|         parser = subparser or self.parser |  | ||||||
|  |  | ||||||
|         parser.add_argument( |  | ||||||
|             '-1', '--one-column', |  | ||||||
|             help='Print exchanges in one column.', |  | ||||||
|             action='store_true', |  | ||||||
|             dest='print_one_column', |  | ||||||
|         ) |  | ||||||
|  |  | ||||||
|     def _build_subcommands(self) -> None: |     def _build_subcommands(self) -> None: | ||||||
|         """ |         """ | ||||||
|         Builds and attaches all subcommands. |         Builds and attaches all subcommands. | ||||||
| @@ -731,94 +494,3 @@ class Arguments(object): | |||||||
|                         stop = int(stops) |                         stop = int(stops) | ||||||
|                 return TimeRange(stype[0], stype[1], start, stop) |                 return TimeRange(stype[0], stype[1], start, stop) | ||||||
|         raise Exception('Incorrect syntax for timerange "%s"' % text) |         raise Exception('Incorrect syntax for timerange "%s"' % text) | ||||||
|  |  | ||||||
|     def common_scripts_options(self, subparser: argparse.ArgumentParser = None) -> None: |  | ||||||
|         """ |  | ||||||
|         Parses arguments common for scripts. |  | ||||||
|         """ |  | ||||||
|         parser = subparser or self.parser |  | ||||||
|  |  | ||||||
|         parser.add_argument( |  | ||||||
|             '-p', '--pairs', |  | ||||||
|             help='Show profits for only these pairs. Pairs are comma-separated.', |  | ||||||
|             dest='pairs', |  | ||||||
|         ) |  | ||||||
|  |  | ||||||
|     def download_data_options(self) -> None: |  | ||||||
|         """ |  | ||||||
|         Parses given arguments for testdata download script |  | ||||||
|         """ |  | ||||||
|         parser = self.parser |  | ||||||
|  |  | ||||||
|         parser.add_argument( |  | ||||||
|             '--pairs-file', |  | ||||||
|             help='File containing a list of pairs to download.', |  | ||||||
|             dest='pairs_file', |  | ||||||
|             metavar='FILE', |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '--days', |  | ||||||
|             help='Download data for given number of days.', |  | ||||||
|             dest='days', |  | ||||||
|             type=check_int_positive, |  | ||||||
|             metavar='INT', |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '--exchange', |  | ||||||
|             help=f'Exchange name (default: `{constants.DEFAULT_EXCHANGE}`). ' |  | ||||||
|                  f'Only valid if no config is provided.', |  | ||||||
|             dest='exchange', |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '-t', '--timeframes', |  | ||||||
|             help=f'Specify which tickers to download. Space-separated list. ' |  | ||||||
|                  f'Default: `{constants.DEFAULT_DOWNLOAD_TICKER_INTERVALS}`.', |  | ||||||
|             choices=['1m', '3m', '5m', '15m', '30m', '1h', '2h', '4h', |  | ||||||
|                      '6h', '8h', '12h', '1d', '3d', '1w'], |  | ||||||
|             nargs='+', |  | ||||||
|             dest='timeframes', |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '--erase', |  | ||||||
|             help='Clean all existing data for the selected exchange/pairs/timeframes.', |  | ||||||
|             dest='erase', |  | ||||||
|             action='store_true' |  | ||||||
|         ) |  | ||||||
|  |  | ||||||
|     def plot_dataframe_options(self) -> None: |  | ||||||
|         """ |  | ||||||
|         Parses given arguments for plot dataframe script |  | ||||||
|         """ |  | ||||||
|         parser = self.parser |  | ||||||
|  |  | ||||||
|         parser.add_argument( |  | ||||||
|             '--indicators1', |  | ||||||
|             help='Set indicators from your strategy you want in the first row of the graph. ' |  | ||||||
|                  'Comma-separated list. Example: `ema3,ema5`. Default: `%(default)s`.', |  | ||||||
|             default='sma,ema3,ema5', |  | ||||||
|             dest='indicators1', |  | ||||||
|         ) |  | ||||||
|  |  | ||||||
|         parser.add_argument( |  | ||||||
|             '--indicators2', |  | ||||||
|             help='Set indicators from your strategy you want in the third row of the graph. ' |  | ||||||
|                  'Comma-separated list. Example: `fastd,fastk`. Default: `%(default)s`.', |  | ||||||
|             default='macd,macdsignal', |  | ||||||
|             dest='indicators2', |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '--plot-limit', |  | ||||||
|             help='Specify tick limit for plotting. Notice: too high values cause huge files. ' |  | ||||||
|                  'Default: %(default)s.', |  | ||||||
|             dest='plot_limit', |  | ||||||
|             default=750, |  | ||||||
|             type=int, |  | ||||||
|         ) |  | ||||||
|         parser.add_argument( |  | ||||||
|             '--trade-source', |  | ||||||
|             help='Specify the source for trades (Can be DB or file (backtest file)) ' |  | ||||||
|                  'Default: %(default)s', |  | ||||||
|             dest='trade_source', |  | ||||||
|             default="file", |  | ||||||
|             choices=["DB", "file"] |  | ||||||
|         ) |  | ||||||
|   | |||||||
| @@ -3,7 +3,8 @@ import argparse | |||||||
|  |  | ||||||
| import pytest | import pytest | ||||||
|  |  | ||||||
| from freqtrade.arguments import Arguments, TimeRange, check_int_positive, ARGS_DOWNLOADER | from freqtrade.arguments import (ARGS_DOWNLOADER, ARGS_PLOT_DATAFRAME, | ||||||
|  |                                  Arguments, TimeRange, check_int_positive) | ||||||
|  |  | ||||||
|  |  | ||||||
| # Parse common command-line-arguments. Used for all tools | # Parse common command-line-arguments. Used for all tools | ||||||
| @@ -49,8 +50,8 @@ def test_parse_args_verbose() -> None: | |||||||
|  |  | ||||||
| def test_common_scripts_options() -> None: | def test_common_scripts_options() -> None: | ||||||
|     arguments = Arguments(['-p', 'ETH/BTC'], '') |     arguments = Arguments(['-p', 'ETH/BTC'], '') | ||||||
|     arguments.common_scripts_options() |     arguments.build_args(ARGS_DOWNLOADER) | ||||||
|     args = arguments.get_parsed_arg() |     args = arguments.parse_args() | ||||||
|     assert args.pairs == 'ETH/BTC' |     assert args.pairs == 'ETH/BTC' | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -195,8 +196,7 @@ def test_plot_dataframe_options() -> None: | |||||||
|         '-p', 'UNITTEST/BTC', |         '-p', 'UNITTEST/BTC', | ||||||
|     ] |     ] | ||||||
|     arguments = Arguments(args, '') |     arguments = Arguments(args, '') | ||||||
|     arguments.common_scripts_options() |     arguments.build_args(ARGS_PLOT_DATAFRAME) | ||||||
|     arguments.plot_dataframe_options() |  | ||||||
|     pargs = arguments.parse_args(True) |     pargs = arguments.parse_args(True) | ||||||
|     assert pargs.indicators1 == "sma10,sma100" |     assert pargs.indicators1 == "sma10,sma100" | ||||||
|     assert pargs.indicators2 == "macd,fastd,fastk" |     assert pargs.indicators2 == "macd,fastd,fastk" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user