From a05e38dbd340dab8500c05fcacb9b59d89baad82 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 12 Jun 2021 09:03:55 +0200 Subject: [PATCH] Require timeframe for plot-profit must be set in config or via --timeframe --- freqtrade/plot/plotting.py | 9 ++++++--- tests/test_plotting.py | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/freqtrade/plot/plotting.py b/freqtrade/plot/plotting.py index f52b0bc81..c1b1232c2 100644 --- a/freqtrade/plot/plotting.py +++ b/freqtrade/plot/plotting.py @@ -47,7 +47,7 @@ def init_plotscript(config, markets: List, startup_candles: int = 0): data = load_data( datadir=config.get('datadir'), pairs=pairs, - timeframe=config.get('timeframe', '5m'), + timeframe=config['timeframe'], timerange=timerange, startup_candles=startup_candles, data_format=config.get('dataformat_ohlcv', 'json'), @@ -56,7 +56,7 @@ def init_plotscript(config, markets: List, startup_candles: int = 0): if startup_candles and data: min_date, max_date = get_timerange(data) logger.info(f"Loading data from {min_date} to {max_date}") - timerange.adjust_start_if_necessary(timeframe_to_seconds(config.get('timeframe', '5m')), + timerange.adjust_start_if_necessary(timeframe_to_seconds(config['timeframe']), startup_candles, min_date) no_trades = False @@ -583,6 +583,9 @@ def plot_profit(config: Dict[str, Any]) -> None: But should be somewhat proportional, and therefor useful in helping out to find a good algorithm. """ + if 'timeframe' not in config: + raise OperationalException('Timeframe must be set in either config or via --timeframe.') + exchange = ExchangeResolver.load_exchange(config['exchange']['name'], config) plot_elements = init_plotscript(config, list(exchange.markets)) trades = plot_elements['trades'] @@ -599,7 +602,7 @@ def plot_profit(config: Dict[str, Any]) -> None: # Create an average close price of all the pairs that were involved. # this could be useful to gauge the overall market trend fig = generate_profit_graph(plot_elements['pairs'], plot_elements['ohlcv'], - trades, config.get('timeframe', '5m'), + trades, config['timeframe'], config.get('stake_currency', '')) store_plot_file(fig, filename='freqtrade-profit-plot.html', directory=config['user_data_dir'] / 'plot', diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 0b1054ced..20f159e3a 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -462,6 +462,10 @@ def test_plot_profit(default_conf, mocker, testdatadir): assert profit_mock.call_args_list[0][0][0] == default_conf['pairs'] assert store_mock.call_args_list[0][1]['auto_open'] is False + del default_conf['timeframe'] + with pytest.raises(OperationalException, match=r"Timeframe must be set.*--timeframe.*"): + plot_profit(default_conf) + @pytest.mark.parametrize("ind1,ind2,plot_conf,exp", [ # No indicators, use plot_conf