We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Plot-scripts require --datadir
## Describe your environment

  * Python Version: 3.7
  * Branch: Develop
  * Last Commit ID:  962d487edb0d28f95d6395c09189a333c436fd20
  
## Describe the problem:

Currently, `freqtrade plot-dataframe` does require either a valid configuration (`--config` or `config.json` in cwd - or `--datadir user_data/data/bittrex` to find the backtest data.
This is because without one of these, the exchange is not known, which is a requirement to find the data in the datadir.

## Possible fixes

* Error and point out that one of the 2 conditions have to be met
* add `--exchange` parameter as alternative (including the above)

* ... other ideas?

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `freqtrade/configuration/arguments.py`
Content:
```
1 """
2 This module contains the argument manager class
3 """
4 import argparse
5 from typing import List, Optional
6 
7 from freqtrade.configuration.cli_options import AVAILABLE_CLI_OPTIONS
8 from freqtrade import constants
9 
10 ARGS_COMMON = ["verbosity", "logfile", "version", "config", "datadir", "user_data_dir"]
11 
12 ARGS_STRATEGY = ["strategy", "strategy_path"]
13 
14 ARGS_MAIN = ARGS_COMMON + ARGS_STRATEGY + ["db_url", "sd_notify"]
15 
16 ARGS_COMMON_OPTIMIZE = ["ticker_interval", "timerange",
17                         "max_open_trades", "stake_amount", "refresh_pairs"]
18 
19 ARGS_BACKTEST = ARGS_COMMON_OPTIMIZE + ["position_stacking", "use_max_market_positions",
20                                         "strategy_list", "export", "exportfilename"]
21 
22 ARGS_HYPEROPT = ARGS_COMMON_OPTIMIZE + ["hyperopt", "hyperopt_path",
23                                         "position_stacking", "epochs", "spaces",
24                                         "use_max_market_positions", "print_all",
25                                         "print_colorized", "print_json", "hyperopt_jobs",
26                                         "hyperopt_random_state", "hyperopt_min_trades",
27                                         "hyperopt_continue", "hyperopt_loss"]
28 
29 ARGS_EDGE = ARGS_COMMON_OPTIMIZE + ["stoploss_range"]
30 
31 ARGS_LIST_EXCHANGES = ["print_one_column"]
32 
33 ARGS_CREATE_USERDIR = ["user_data_dir"]
34 
35 ARGS_DOWNLOAD_DATA = ["pairs", "pairs_file", "days", "exchange", "timeframes", "erase"]
36 
37 ARGS_PLOT_DATAFRAME = ["pairs", "indicators1", "indicators2", "plot_limit", "db_url",
38                        "trade_source", "export", "exportfilename", "timerange", "ticker_interval"]
39 
40 ARGS_PLOT_PROFIT = ["pairs", "timerange", "export", "exportfilename", "db_url",
41                     "trade_source", "ticker_interval"]
42 
43 NO_CONF_REQURIED = ["download-data", "plot-dataframe", "plot-profit"]
44 
45 
46 class Arguments(object):
47     """
48     Arguments Class. Manage the arguments received by the cli
49     """
50     def __init__(self, args: Optional[List[str]]) -> None:
51         self.args = args
52         self._parsed_arg: Optional[argparse.Namespace] = None
53         self.parser = argparse.ArgumentParser(description='Free, open source crypto trading bot')
54 
55     def _load_args(self) -> None:
56         self._build_args(optionlist=ARGS_MAIN)
57         self._build_subcommands()
58 
59     def get_parsed_arg(self) -> argparse.Namespace:
60         """
61         Return the list of arguments
62         :return: List[str] List of arguments
63         """
64         if self._parsed_arg is None:
65             self._load_args()
66             self._parsed_arg = self._parse_args()
67 
68         return self._parsed_arg
69 
70     def _parse_args(self) -> argparse.Namespace:
71         """
72         Parses given arguments and returns an argparse Namespace instance.
73         """
74         parsed_arg = self.parser.parse_args(self.args)
75 
76         # Workaround issue in argparse with action='append' and default value
77         # (see https://bugs.python.org/issue16399)
78         # Allow no-config for certain commands (like downloading / plotting)
79         if (parsed_arg.config is None
80                 and not ('subparser' in parsed_arg and parsed_arg.subparser in NO_CONF_REQURIED)):
81             parsed_arg.config = [constants.DEFAULT_CONFIG]
82 
83         return parsed_arg
84 
85     def _build_args(self, optionlist, parser=None):
86         parser = parser or self.parser
87 
88         for val in optionlist:
89             opt = AVAILABLE_CLI_OPTIONS[val]
90             parser.add_argument(*opt.cli, dest=val, **opt.kwargs)
91 
92     def _build_subcommands(self) -> None:
93         """
94         Builds and attaches all subcommands.
95         :return: None
96         """
97         from freqtrade.optimize import start_backtesting, start_hyperopt, start_edge
98         from freqtrade.utils import start_create_userdir, start_download_data, start_list_exchanges
99 
100         subparsers = self.parser.add_subparsers(dest='subparser')
101 
102         # Add backtesting subcommand
103         backtesting_cmd = subparsers.add_parser('backtesting', help='Backtesting module.')
104         backtesting_cmd.set_defaults(func=start_backtesting)
105         self._build_args(optionlist=ARGS_BACKTEST, parser=backtesting_cmd)
106 
107         # Add edge subcommand
108         edge_cmd = subparsers.add_parser('edge', help='Edge module.')
109         edge_cmd.set_defaults(func=start_edge)
110         self._build_args(optionlist=ARGS_EDGE, parser=edge_cmd)
111 
112         # Add hyperopt subcommand
113         hyperopt_cmd = subparsers.add_parser('hyperopt', help='Hyperopt module.')
114         hyperopt_cmd.set_defaults(func=start_hyperopt)
115         self._build_args(optionlist=ARGS_HYPEROPT, parser=hyperopt_cmd)
116 
117         # add create-userdir subcommand
118         create_userdir_cmd = subparsers.add_parser('create-userdir',
119                                                    help="Create user-data directory.")
120         create_userdir_cmd.set_defaults(func=start_create_userdir)
121         self._build_args(optionlist=ARGS_CREATE_USERDIR, parser=create_userdir_cmd)
122 
123         # Add list-exchanges subcommand
124         list_exchanges_cmd = subparsers.add_parser(
125             'list-exchanges',
126             help='Print available exchanges.'
127         )
128         list_exchanges_cmd.set_defaults(func=start_list_exchanges)
129         self._build_args(optionlist=ARGS_LIST_EXCHANGES, parser=list_exchanges_cmd)
130 
131         # Add download-data subcommand
132         download_data_cmd = subparsers.add_parser(
133             'download-data',
134             help='Download backtesting data.'
135         )
136         download_data_cmd.set_defaults(func=start_download_data)
137         self._build_args(optionlist=ARGS_DOWNLOAD_DATA, parser=download_data_cmd)
138 
139         # Add Plotting subcommand
140         from freqtrade.plot.plot_utils import start_plot_dataframe, start_plot_profit
141         plot_dataframe_cmd = subparsers.add_parser(
142             'plot-dataframe',
143             help='Plot candles with indicators.'
144         )
145         plot_dataframe_cmd.set_defaults(func=start_plot_dataframe)
146         self._build_args(optionlist=ARGS_PLOT_DATAFRAME, parser=plot_dataframe_cmd)
147 
148         # Plot profit
149         plot_profit_cmd = subparsers.add_parser(
150             'plot-profit',
151             help='Generate plot showing profits.'
152         )
153         plot_profit_cmd.set_defaults(func=start_plot_profit)
154         self._build_args(optionlist=ARGS_PLOT_PROFIT, parser=plot_profit_cmd)
155
```

Path: `freqtrade/plot/plot_utils.py`
Content:
```
1 from argparse import Namespace
2 
3 from freqtrade.state import RunMode
4 from freqtrade.utils import setup_utils_configuration
5 
6 
7 def start_plot_dataframe(args: Namespace) -> None:
8     """
9     Entrypoint for dataframe plotting
10     """
11     # Import here to avoid errors if plot-dependencies are not installed.
12     from freqtrade.plot.plotting import analyse_and_plot_pairs
13     config = setup_utils_configuration(args, RunMode.PLOT)
14 
15     analyse_and_plot_pairs(config)
16 
17 
18 def start_plot_profit(args: Namespace) -> None:
19     """
20     Entrypoint for plot_profit
21     """
22     # Import here to avoid errors if plot-dependencies are not installed.
23     from freqtrade.plot.plotting import plot_profit
24     config = setup_utils_configuration(args, RunMode.PLOT)
25 
26     plot_profit(config)
27
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/freqtrade/configuration/arguments.py b/freqtrade/configuration/arguments.py
--- a/freqtrade/configuration/arguments.py
+++ b/freqtrade/configuration/arguments.py
@@ -3,6 +3,7 @@
 """
 import argparse
 from typing import List, Optional
+from pathlib import Path
 
 from freqtrade.configuration.cli_options import AVAILABLE_CLI_OPTIONS
 from freqtrade import constants
@@ -73,11 +74,13 @@
         """
         parsed_arg = self.parser.parse_args(self.args)
 
+        # When no config is provided, but a config exists, use that configuration!
+
         # Workaround issue in argparse with action='append' and default value
         # (see https://bugs.python.org/issue16399)
         # Allow no-config for certain commands (like downloading / plotting)
-        if (parsed_arg.config is None
-                and not ('subparser' in parsed_arg and parsed_arg.subparser in NO_CONF_REQURIED)):
+        if (parsed_arg.config is None and ((Path.cwd() / constants.DEFAULT_CONFIG).is_file() or
+           not ('subparser' in parsed_arg and parsed_arg.subparser in NO_CONF_REQURIED))):
             parsed_arg.config = [constants.DEFAULT_CONFIG]
 
         return parsed_arg
diff --git a/freqtrade/plot/plot_utils.py b/freqtrade/plot/plot_utils.py
--- a/freqtrade/plot/plot_utils.py
+++ b/freqtrade/plot/plot_utils.py
@@ -1,15 +1,24 @@
 from argparse import Namespace
-
+from freqtrade import OperationalException
 from freqtrade.state import RunMode
 from freqtrade.utils import setup_utils_configuration
 
 
+def validate_plot_args(args: Namespace):
+    args_tmp = vars(args)
+    if not args_tmp.get('datadir') and not args_tmp.get('config'):
+        raise OperationalException(
+            "You need to specify either `--datadir` or `--config` "
+            "for plot-profit and plot-dataframe.")
+
+
 def start_plot_dataframe(args: Namespace) -> None:
     """
     Entrypoint for dataframe plotting
     """
     # Import here to avoid errors if plot-dependencies are not installed.
     from freqtrade.plot.plotting import analyse_and_plot_pairs
+    validate_plot_args(args)
     config = setup_utils_configuration(args, RunMode.PLOT)
 
     analyse_and_plot_pairs(config)
@@ -21,6 +30,7 @@
     """
     # Import here to avoid errors if plot-dependencies are not installed.
     from freqtrade.plot.plotting import plot_profit
+    validate_plot_args(args)
     config = setup_utils_configuration(args, RunMode.PLOT)
 
     plot_profit(config)

{"golden_diff": "diff --git a/freqtrade/configuration/arguments.py b/freqtrade/configuration/arguments.py\n--- a/freqtrade/configuration/arguments.py\n+++ b/freqtrade/configuration/arguments.py\n@@ -3,6 +3,7 @@\n \"\"\"\n import argparse\n from typing import List, Optional\n+from pathlib import Path\n \n from freqtrade.configuration.cli_options import AVAILABLE_CLI_OPTIONS\n from freqtrade import constants\n@@ -73,11 +74,13 @@\n         \"\"\"\n         parsed_arg = self.parser.parse_args(self.args)\n \n+        # When no config is provided, but a config exists, use that configuration!\n+\n         # Workaround issue in argparse with action='append' and default value\n         # (see https://bugs.python.org/issue16399)\n         # Allow no-config for certain commands (like downloading / plotting)\n-        if (parsed_arg.config is None\n-                and not ('subparser' in parsed_arg and parsed_arg.subparser in NO_CONF_REQURIED)):\n+        if (parsed_arg.config is None and ((Path.cwd() / constants.DEFAULT_CONFIG).is_file() or\n+           not ('subparser' in parsed_arg and parsed_arg.subparser in NO_CONF_REQURIED))):\n             parsed_arg.config = [constants.DEFAULT_CONFIG]\n \n         return parsed_arg\ndiff --git a/freqtrade/plot/plot_utils.py b/freqtrade/plot/plot_utils.py\n--- a/freqtrade/plot/plot_utils.py\n+++ b/freqtrade/plot/plot_utils.py\n@@ -1,15 +1,24 @@\n from argparse import Namespace\n-\n+from freqtrade import OperationalException\n from freqtrade.state import RunMode\n from freqtrade.utils import setup_utils_configuration\n \n \n+def validate_plot_args(args: Namespace):\n+    args_tmp = vars(args)\n+    if not args_tmp.get('datadir') and not args_tmp.get('config'):\n+        raise OperationalException(\n+            \"You need to specify either `--datadir` or `--config` \"\n+            \"for plot-profit and plot-dataframe.\")\n+\n+\n def start_plot_dataframe(args: Namespace) -> None:\n     \"\"\"\n     Entrypoint for dataframe plotting\n     \"\"\"\n     # Import here to avoid errors if plot-dependencies are not installed.\n     from freqtrade.plot.plotting import analyse_and_plot_pairs\n+    validate_plot_args(args)\n     config = setup_utils_configuration(args, RunMode.PLOT)\n \n     analyse_and_plot_pairs(config)\n@@ -21,6 +30,7 @@\n     \"\"\"\n     # Import here to avoid errors if plot-dependencies are not installed.\n     from freqtrade.plot.plotting import plot_profit\n+    validate_plot_args(args)\n     config = setup_utils_configuration(args, RunMode.PLOT)\n \n     plot_profit(config)\n", "issue": "Plot-scripts require --datadir\n## Describe your environment\r\n\r\n  * Python Version: 3.7\r\n  * Branch: Develop\r\n  * Last Commit ID:  962d487edb0d28f95d6395c09189a333c436fd20\r\n  \r\n## Describe the problem:\r\n\r\nCurrently, `freqtrade plot-dataframe` does require either a valid configuration (`--config` or `config.json` in cwd - or `--datadir user_data/data/bittrex` to find the backtest data.\r\nThis is because without one of these, the exchange is not known, which is a requirement to find the data in the datadir.\r\n\r\n## Possible fixes\r\n\r\n* Error and point out that one of the 2 conditions have to be met\r\n* add `--exchange` parameter as alternative (including the above)\r\n\r\n* ... other ideas?\n", "before_files": [{"content": "\"\"\"\nThis module contains the argument manager class\n\"\"\"\nimport argparse\nfrom typing import List, Optional\n\nfrom freqtrade.configuration.cli_options import AVAILABLE_CLI_OPTIONS\nfrom freqtrade import constants\n\nARGS_COMMON = [\"verbosity\", \"logfile\", \"version\", \"config\", \"datadir\", \"user_data_dir\"]\n\nARGS_STRATEGY = [\"strategy\", \"strategy_path\"]\n\nARGS_MAIN = ARGS_COMMON + ARGS_STRATEGY + [\"db_url\", \"sd_notify\"]\n\nARGS_COMMON_OPTIMIZE = [\"ticker_interval\", \"timerange\",\n                        \"max_open_trades\", \"stake_amount\", \"refresh_pairs\"]\n\nARGS_BACKTEST = ARGS_COMMON_OPTIMIZE + [\"position_stacking\", \"use_max_market_positions\",\n                                        \"strategy_list\", \"export\", \"exportfilename\"]\n\nARGS_HYPEROPT = ARGS_COMMON_OPTIMIZE + [\"hyperopt\", \"hyperopt_path\",\n                                        \"position_stacking\", \"epochs\", \"spaces\",\n                                        \"use_max_market_positions\", \"print_all\",\n                                        \"print_colorized\", \"print_json\", \"hyperopt_jobs\",\n                                        \"hyperopt_random_state\", \"hyperopt_min_trades\",\n                                        \"hyperopt_continue\", \"hyperopt_loss\"]\n\nARGS_EDGE = ARGS_COMMON_OPTIMIZE + [\"stoploss_range\"]\n\nARGS_LIST_EXCHANGES = [\"print_one_column\"]\n\nARGS_CREATE_USERDIR = [\"user_data_dir\"]\n\nARGS_DOWNLOAD_DATA = [\"pairs\", \"pairs_file\", \"days\", \"exchange\", \"timeframes\", \"erase\"]\n\nARGS_PLOT_DATAFRAME = [\"pairs\", \"indicators1\", \"indicators2\", \"plot_limit\", \"db_url\",\n                       \"trade_source\", \"export\", \"exportfilename\", \"timerange\", \"ticker_interval\"]\n\nARGS_PLOT_PROFIT = [\"pairs\", \"timerange\", \"export\", \"exportfilename\", \"db_url\",\n                    \"trade_source\", \"ticker_interval\"]\n\nNO_CONF_REQURIED = [\"download-data\", \"plot-dataframe\", \"plot-profit\"]\n\n\nclass Arguments(object):\n    \"\"\"\n    Arguments Class. Manage the arguments received by the cli\n    \"\"\"\n    def __init__(self, args: Optional[List[str]]) -> None:\n        self.args = args\n        self._parsed_arg: Optional[argparse.Namespace] = None\n        self.parser = argparse.ArgumentParser(description='Free, open source crypto trading bot')\n\n    def _load_args(self) -> None:\n        self._build_args(optionlist=ARGS_MAIN)\n        self._build_subcommands()\n\n    def get_parsed_arg(self) -> argparse.Namespace:\n        \"\"\"\n        Return the list of arguments\n        :return: List[str] List of arguments\n        \"\"\"\n        if self._parsed_arg is None:\n            self._load_args()\n            self._parsed_arg = self._parse_args()\n\n        return self._parsed_arg\n\n    def _parse_args(self) -> argparse.Namespace:\n        \"\"\"\n        Parses given arguments and returns an argparse Namespace instance.\n        \"\"\"\n        parsed_arg = self.parser.parse_args(self.args)\n\n        # Workaround issue in argparse with action='append' and default value\n        # (see https://bugs.python.org/issue16399)\n        # Allow no-config for certain commands (like downloading / plotting)\n        if (parsed_arg.config is None\n                and not ('subparser' in parsed_arg and parsed_arg.subparser in NO_CONF_REQURIED)):\n            parsed_arg.config = [constants.DEFAULT_CONFIG]\n\n        return parsed_arg\n\n    def _build_args(self, optionlist, parser=None):\n        parser = parser or self.parser\n\n        for val in optionlist:\n            opt = AVAILABLE_CLI_OPTIONS[val]\n            parser.add_argument(*opt.cli, dest=val, **opt.kwargs)\n\n    def _build_subcommands(self) -> None:\n        \"\"\"\n        Builds and attaches all subcommands.\n        :return: None\n        \"\"\"\n        from freqtrade.optimize import start_backtesting, start_hyperopt, start_edge\n        from freqtrade.utils import start_create_userdir, start_download_data, start_list_exchanges\n\n        subparsers = self.parser.add_subparsers(dest='subparser')\n\n        # Add backtesting subcommand\n        backtesting_cmd = subparsers.add_parser('backtesting', help='Backtesting module.')\n        backtesting_cmd.set_defaults(func=start_backtesting)\n        self._build_args(optionlist=ARGS_BACKTEST, parser=backtesting_cmd)\n\n        # Add edge subcommand\n        edge_cmd = subparsers.add_parser('edge', help='Edge module.')\n        edge_cmd.set_defaults(func=start_edge)\n        self._build_args(optionlist=ARGS_EDGE, parser=edge_cmd)\n\n        # Add hyperopt subcommand\n        hyperopt_cmd = subparsers.add_parser('hyperopt', help='Hyperopt module.')\n        hyperopt_cmd.set_defaults(func=start_hyperopt)\n        self._build_args(optionlist=ARGS_HYPEROPT, parser=hyperopt_cmd)\n\n        # add create-userdir subcommand\n        create_userdir_cmd = subparsers.add_parser('create-userdir',\n                                                   help=\"Create user-data directory.\")\n        create_userdir_cmd.set_defaults(func=start_create_userdir)\n        self._build_args(optionlist=ARGS_CREATE_USERDIR, parser=create_userdir_cmd)\n\n        # Add list-exchanges subcommand\n        list_exchanges_cmd = subparsers.add_parser(\n            'list-exchanges',\n            help='Print available exchanges.'\n        )\n        list_exchanges_cmd.set_defaults(func=start_list_exchanges)\n        self._build_args(optionlist=ARGS_LIST_EXCHANGES, parser=list_exchanges_cmd)\n\n        # Add download-data subcommand\n        download_data_cmd = subparsers.add_parser(\n            'download-data',\n            help='Download backtesting data.'\n        )\n        download_data_cmd.set_defaults(func=start_download_data)\n        self._build_args(optionlist=ARGS_DOWNLOAD_DATA, parser=download_data_cmd)\n\n        # Add Plotting subcommand\n        from freqtrade.plot.plot_utils import start_plot_dataframe, start_plot_profit\n        plot_dataframe_cmd = subparsers.add_parser(\n            'plot-dataframe',\n            help='Plot candles with indicators.'\n        )\n        plot_dataframe_cmd.set_defaults(func=start_plot_dataframe)\n        self._build_args(optionlist=ARGS_PLOT_DATAFRAME, parser=plot_dataframe_cmd)\n\n        # Plot profit\n        plot_profit_cmd = subparsers.add_parser(\n            'plot-profit',\n            help='Generate plot showing profits.'\n        )\n        plot_profit_cmd.set_defaults(func=start_plot_profit)\n        self._build_args(optionlist=ARGS_PLOT_PROFIT, parser=plot_profit_cmd)\n", "path": "freqtrade/configuration/arguments.py"}, {"content": "from argparse import Namespace\n\nfrom freqtrade.state import RunMode\nfrom freqtrade.utils import setup_utils_configuration\n\n\ndef start_plot_dataframe(args: Namespace) -> None:\n    \"\"\"\n    Entrypoint for dataframe plotting\n    \"\"\"\n    # Import here to avoid errors if plot-dependencies are not installed.\n    from freqtrade.plot.plotting import analyse_and_plot_pairs\n    config = setup_utils_configuration(args, RunMode.PLOT)\n\n    analyse_and_plot_pairs(config)\n\n\ndef start_plot_profit(args: Namespace) -> None:\n    \"\"\"\n    Entrypoint for plot_profit\n    \"\"\"\n    # Import here to avoid errors if plot-dependencies are not installed.\n    from freqtrade.plot.plotting import plot_profit\n    config = setup_utils_configuration(args, RunMode.PLOT)\n\n    plot_profit(config)\n", "path": "freqtrade/plot/plot_utils.py"}], "after_files": [{"content": "\"\"\"\nThis module contains the argument manager class\n\"\"\"\nimport argparse\nfrom typing import List, Optional\nfrom pathlib import Path\n\nfrom freqtrade.configuration.cli_options import AVAILABLE_CLI_OPTIONS\nfrom freqtrade import constants\n\nARGS_COMMON = [\"verbosity\", \"logfile\", \"version\", \"config\", \"datadir\", \"user_data_dir\"]\n\nARGS_STRATEGY = [\"strategy\", \"strategy_path\"]\n\nARGS_MAIN = ARGS_COMMON + ARGS_STRATEGY + [\"db_url\", \"sd_notify\"]\n\nARGS_COMMON_OPTIMIZE = [\"ticker_interval\", \"timerange\",\n                        \"max_open_trades\", \"stake_amount\", \"refresh_pairs\"]\n\nARGS_BACKTEST = ARGS_COMMON_OPTIMIZE + [\"position_stacking\", \"use_max_market_positions\",\n                                        \"strategy_list\", \"export\", \"exportfilename\"]\n\nARGS_HYPEROPT = ARGS_COMMON_OPTIMIZE + [\"hyperopt\", \"hyperopt_path\",\n                                        \"position_stacking\", \"epochs\", \"spaces\",\n                                        \"use_max_market_positions\", \"print_all\",\n                                        \"print_colorized\", \"print_json\", \"hyperopt_jobs\",\n                                        \"hyperopt_random_state\", \"hyperopt_min_trades\",\n                                        \"hyperopt_continue\", \"hyperopt_loss\"]\n\nARGS_EDGE = ARGS_COMMON_OPTIMIZE + [\"stoploss_range\"]\n\nARGS_LIST_EXCHANGES = [\"print_one_column\"]\n\nARGS_CREATE_USERDIR = [\"user_data_dir\"]\n\nARGS_DOWNLOAD_DATA = [\"pairs\", \"pairs_file\", \"days\", \"exchange\", \"timeframes\", \"erase\"]\n\nARGS_PLOT_DATAFRAME = [\"pairs\", \"indicators1\", \"indicators2\", \"plot_limit\", \"db_url\",\n                       \"trade_source\", \"export\", \"exportfilename\", \"timerange\", \"ticker_interval\"]\n\nARGS_PLOT_PROFIT = [\"pairs\", \"timerange\", \"export\", \"exportfilename\", \"db_url\",\n                    \"trade_source\", \"ticker_interval\"]\n\nNO_CONF_REQURIED = [\"download-data\", \"plot-dataframe\", \"plot-profit\"]\n\n\nclass Arguments(object):\n    \"\"\"\n    Arguments Class. Manage the arguments received by the cli\n    \"\"\"\n    def __init__(self, args: Optional[List[str]]) -> None:\n        self.args = args\n        self._parsed_arg: Optional[argparse.Namespace] = None\n        self.parser = argparse.ArgumentParser(description='Free, open source crypto trading bot')\n\n    def _load_args(self) -> None:\n        self._build_args(optionlist=ARGS_MAIN)\n        self._build_subcommands()\n\n    def get_parsed_arg(self) -> argparse.Namespace:\n        \"\"\"\n        Return the list of arguments\n        :return: List[str] List of arguments\n        \"\"\"\n        if self._parsed_arg is None:\n            self._load_args()\n            self._parsed_arg = self._parse_args()\n\n        return self._parsed_arg\n\n    def _parse_args(self) -> argparse.Namespace:\n        \"\"\"\n        Parses given arguments and returns an argparse Namespace instance.\n        \"\"\"\n        parsed_arg = self.parser.parse_args(self.args)\n\n        # When no config is provided, but a config exists, use that configuration!\n\n        # Workaround issue in argparse with action='append' and default value\n        # (see https://bugs.python.org/issue16399)\n        # Allow no-config for certain commands (like downloading / plotting)\n        if (parsed_arg.config is None and ((Path.cwd() / constants.DEFAULT_CONFIG).is_file() or\n           not ('subparser' in parsed_arg and parsed_arg.subparser in NO_CONF_REQURIED))):\n            parsed_arg.config = [constants.DEFAULT_CONFIG]\n\n        return parsed_arg\n\n    def _build_args(self, optionlist, parser=None):\n        parser = parser or self.parser\n\n        for val in optionlist:\n            opt = AVAILABLE_CLI_OPTIONS[val]\n            parser.add_argument(*opt.cli, dest=val, **opt.kwargs)\n\n    def _build_subcommands(self) -> None:\n        \"\"\"\n        Builds and attaches all subcommands.\n        :return: None\n        \"\"\"\n        from freqtrade.optimize import start_backtesting, start_hyperopt, start_edge\n        from freqtrade.utils import start_create_userdir, start_download_data, start_list_exchanges\n\n        subparsers = self.parser.add_subparsers(dest='subparser')\n\n        # Add backtesting subcommand\n        backtesting_cmd = subparsers.add_parser('backtesting', help='Backtesting module.')\n        backtesting_cmd.set_defaults(func=start_backtesting)\n        self._build_args(optionlist=ARGS_BACKTEST, parser=backtesting_cmd)\n\n        # Add edge subcommand\n        edge_cmd = subparsers.add_parser('edge', help='Edge module.')\n        edge_cmd.set_defaults(func=start_edge)\n        self._build_args(optionlist=ARGS_EDGE, parser=edge_cmd)\n\n        # Add hyperopt subcommand\n        hyperopt_cmd = subparsers.add_parser('hyperopt', help='Hyperopt module.')\n        hyperopt_cmd.set_defaults(func=start_hyperopt)\n        self._build_args(optionlist=ARGS_HYPEROPT, parser=hyperopt_cmd)\n\n        # add create-userdir subcommand\n        create_userdir_cmd = subparsers.add_parser('create-userdir',\n                                                   help=\"Create user-data directory.\")\n        create_userdir_cmd.set_defaults(func=start_create_userdir)\n        self._build_args(optionlist=ARGS_CREATE_USERDIR, parser=create_userdir_cmd)\n\n        # Add list-exchanges subcommand\n        list_exchanges_cmd = subparsers.add_parser(\n            'list-exchanges',\n            help='Print available exchanges.'\n        )\n        list_exchanges_cmd.set_defaults(func=start_list_exchanges)\n        self._build_args(optionlist=ARGS_LIST_EXCHANGES, parser=list_exchanges_cmd)\n\n        # Add download-data subcommand\n        download_data_cmd = subparsers.add_parser(\n            'download-data',\n            help='Download backtesting data.'\n        )\n        download_data_cmd.set_defaults(func=start_download_data)\n        self._build_args(optionlist=ARGS_DOWNLOAD_DATA, parser=download_data_cmd)\n\n        # Add Plotting subcommand\n        from freqtrade.plot.plot_utils import start_plot_dataframe, start_plot_profit\n        plot_dataframe_cmd = subparsers.add_parser(\n            'plot-dataframe',\n            help='Plot candles with indicators.'\n        )\n        plot_dataframe_cmd.set_defaults(func=start_plot_dataframe)\n        self._build_args(optionlist=ARGS_PLOT_DATAFRAME, parser=plot_dataframe_cmd)\n\n        # Plot profit\n        plot_profit_cmd = subparsers.add_parser(\n            'plot-profit',\n            help='Generate plot showing profits.'\n        )\n        plot_profit_cmd.set_defaults(func=start_plot_profit)\n        self._build_args(optionlist=ARGS_PLOT_PROFIT, parser=plot_profit_cmd)\n", "path": "freqtrade/configuration/arguments.py"}, {"content": "from argparse import Namespace\nfrom freqtrade import OperationalException\nfrom freqtrade.state import RunMode\nfrom freqtrade.utils import setup_utils_configuration\n\n\ndef validate_plot_args(args: Namespace):\n    args_tmp = vars(args)\n    if not args_tmp.get('datadir') and not args_tmp.get('config'):\n        raise OperationalException(\n            \"You need to specify either `--datadir` or `--config` \"\n            \"for plot-profit and plot-dataframe.\")\n\n\ndef start_plot_dataframe(args: Namespace) -> None:\n    \"\"\"\n    Entrypoint for dataframe plotting\n    \"\"\"\n    # Import here to avoid errors if plot-dependencies are not installed.\n    from freqtrade.plot.plotting import analyse_and_plot_pairs\n    validate_plot_args(args)\n    config = setup_utils_configuration(args, RunMode.PLOT)\n\n    analyse_and_plot_pairs(config)\n\n\ndef start_plot_profit(args: Namespace) -> None:\n    \"\"\"\n    Entrypoint for plot_profit\n    \"\"\"\n    # Import here to avoid errors if plot-dependencies are not installed.\n    from freqtrade.plot.plotting import plot_profit\n    validate_plot_args(args)\n    config = setup_utils_configuration(args, RunMode.PLOT)\n\n    plot_profit(config)\n", "path": "freqtrade/plot/plot_utils.py"}]}