From 2fdda8e448a5147f0abef0ba0fe26911909e8572 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 30 Dec 2020 08:30:41 +0100 Subject: [PATCH] plot-profit should fail gracefully if no trade is within the selected timerange closes #4119 --- freqtrade/plot/plotting.py | 2 ++ tests/test_plotting.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/freqtrade/plot/plotting.py b/freqtrade/plot/plotting.py index 497218deb..40e3da9c9 100644 --- a/freqtrade/plot/plotting.py +++ b/freqtrade/plot/plotting.py @@ -444,6 +444,8 @@ def generate_profit_graph(pairs: str, data: Dict[str, pd.DataFrame], # Trim trades to available OHLCV data trades = extract_trades_of_period(df_comb, trades, date_index=True) + if len(trades) == 0: + raise OperationalException('No trades found in selected timerange.') # Add combined cumulative profit df_comb = create_cum_profit(df_comb, trades, 'cum_profit', timeframe) diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 42847ca50..8e7b0ef7c 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -353,6 +353,10 @@ def test_generate_profit_graph(testdatadir): profit_pair = find_trace_in_fig_data(figure.data, f"Profit {pair}") assert isinstance(profit_pair, go.Scatter) + with pytest.raises(OperationalException, match=r"No trades found.*"): + # Pair cannot be empty - so it's an empty dataframe. + generate_profit_graph(pairs, data, trades.loc[trades['pair'].isnull()], timeframe="5m") + def test_start_plot_dataframe(mocker): aup = mocker.patch("freqtrade.plot.plotting.load_and_plot_trades", MagicMock())