Merge pull request #2217 from freqtrade/fix/plot_config

Always use config.json if it's available
This commit is contained in:
hroff-1902 2019-09-06 01:12:03 +03:00 committed by GitHub
commit ee68f743c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 3 deletions

View File

@ -3,6 +3,7 @@ This module contains the argument manager class
""" """
import argparse import argparse
from typing import List, Optional from typing import List, Optional
from pathlib import Path
from freqtrade.configuration.cli_options import AVAILABLE_CLI_OPTIONS from freqtrade.configuration.cli_options import AVAILABLE_CLI_OPTIONS
from freqtrade import constants from freqtrade import constants
@ -73,11 +74,13 @@ class Arguments(object):
""" """
parsed_arg = self.parser.parse_args(self.args) 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 # Workaround issue in argparse with action='append' and default value
# (see https://bugs.python.org/issue16399) # (see https://bugs.python.org/issue16399)
# Allow no-config for certain commands (like downloading / plotting) # Allow no-config for certain commands (like downloading / plotting)
if (parsed_arg.config is None if (parsed_arg.config is None and ((Path.cwd() / constants.DEFAULT_CONFIG).is_file() or
and not ('subparser' in parsed_arg and parsed_arg.subparser in NO_CONF_REQURIED)): not ('subparser' in parsed_arg and parsed_arg.subparser in NO_CONF_REQURIED))):
parsed_arg.config = [constants.DEFAULT_CONFIG] parsed_arg.config = [constants.DEFAULT_CONFIG]
return parsed_arg return parsed_arg

View File

@ -1,15 +1,24 @@
from argparse import Namespace from argparse import Namespace
from freqtrade import OperationalException
from freqtrade.state import RunMode from freqtrade.state import RunMode
from freqtrade.utils import setup_utils_configuration 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: def start_plot_dataframe(args: Namespace) -> None:
""" """
Entrypoint for dataframe plotting Entrypoint for dataframe plotting
""" """
# Import here to avoid errors if plot-dependencies are not installed. # Import here to avoid errors if plot-dependencies are not installed.
from freqtrade.plot.plotting import analyse_and_plot_pairs from freqtrade.plot.plotting import analyse_and_plot_pairs
validate_plot_args(args)
config = setup_utils_configuration(args, RunMode.PLOT) config = setup_utils_configuration(args, RunMode.PLOT)
analyse_and_plot_pairs(config) analyse_and_plot_pairs(config)
@ -21,6 +30,7 @@ def start_plot_profit(args: Namespace) -> None:
""" """
# Import here to avoid errors if plot-dependencies are not installed. # Import here to avoid errors if plot-dependencies are not installed.
from freqtrade.plot.plotting import plot_profit from freqtrade.plot.plotting import plot_profit
validate_plot_args(args)
config = setup_utils_configuration(args, RunMode.PLOT) config = setup_utils_configuration(args, RunMode.PLOT)
plot_profit(config) plot_profit(config)

View File

@ -871,6 +871,8 @@ def test_pairlist_resolving_fallback(mocker):
] ]
args = Arguments(arglist).get_parsed_arg() args = Arguments(arglist).get_parsed_arg()
# Fix flaky tests if config.json exists
args.config = None
configuration = Configuration(args) configuration = Configuration(args)
config = configuration.get_config() config = configuration.get_config()

View File

@ -4,8 +4,10 @@ from pathlib import Path
from unittest.mock import MagicMock from unittest.mock import MagicMock
import plotly.graph_objects as go import plotly.graph_objects as go
import pytest
from plotly.subplots import make_subplots from plotly.subplots import make_subplots
from freqtrade import OperationalException
from freqtrade.configuration import TimeRange from freqtrade.configuration import TimeRange
from freqtrade.data import history from freqtrade.data import history
from freqtrade.data.btanalysis import create_cum_profit, load_backtest_data from freqtrade.data.btanalysis import create_cum_profit, load_backtest_data
@ -335,6 +337,15 @@ def test_start_plot_profit(mocker):
assert called_config['pairs'] == ["ETH/BTC"] assert called_config['pairs'] == ["ETH/BTC"]
def test_start_plot_profit_error(mocker):
args = [
"plot-profit",
"--pairs", "ETH/BTC"
]
with pytest.raises(OperationalException):
start_plot_profit(get_args(args))
def test_plot_profit(default_conf, mocker, caplog): def test_plot_profit(default_conf, mocker, caplog):
default_conf['trade_source'] = 'file' default_conf['trade_source'] = 'file'
default_conf["datadir"] = history.make_testdata_path(None) default_conf["datadir"] = history.make_testdata_path(None)