diff --git a/freqtrade/data/btanalysis.py b/freqtrade/data/btanalysis.py index 36d8aedbb..992100cbd 100644 --- a/freqtrade/data/btanalysis.py +++ b/freqtrade/data/btanalysis.py @@ -112,16 +112,16 @@ def load_trades_from_db(db_url: str) -> pd.DataFrame: return trades -def load_trades(config) -> pd.DataFrame: +def load_trades(source: str, db_url: str, exportfilename: str) -> pd.DataFrame: """ Based on configuration option "trade_source": * loads data from DB (using `db_url`) * loads data from backtestfile (using `exportfilename`) """ - if config["trade_source"] == "DB": - return load_trades_from_db(config["db_url"]) - elif config["trade_source"] == "file": - return load_backtest_data(Path(config["exportfilename"])) + if source == "DB": + return load_trades_from_db(db_url) + elif source == "file": + return load_backtest_data(Path(exportfilename)) def extract_trades_of_period(dataframe: pd.DataFrame, trades: pd.DataFrame) -> pd.DataFrame: diff --git a/freqtrade/plot/plotting.py b/freqtrade/plot/plotting.py index a057d3d94..900e9e90c 100644 --- a/freqtrade/plot/plotting.py +++ b/freqtrade/plot/plotting.py @@ -45,7 +45,10 @@ def init_plotscript(config): timerange=timerange, ) - trades = load_trades(config) + trades = load_trades(config['trade_source'], + db_url=config.get('db_url'), + exportfilename=config.get('exportfilename'), + ) return {"tickers": tickers, "trades": trades, "pairs": pairs, diff --git a/freqtrade/tests/data/test_btanalysis.py b/freqtrade/tests/data/test_btanalysis.py index cf8cae566..90602b4fc 100644 --- a/freqtrade/tests/data/test_btanalysis.py +++ b/freqtrade/tests/data/test_btanalysis.py @@ -89,17 +89,20 @@ def test_load_trades(default_conf, mocker): db_mock = mocker.patch("freqtrade.data.btanalysis.load_trades_from_db", MagicMock()) bt_mock = mocker.patch("freqtrade.data.btanalysis.load_backtest_data", MagicMock()) - default_conf['trade_source'] = "DB" - load_trades(default_conf) + load_trades("DB", + db_url=default_conf.get('db_url'), + exportfilename=default_conf.get('exportfilename'), + ) assert db_mock.call_count == 1 assert bt_mock.call_count == 0 db_mock.reset_mock() bt_mock.reset_mock() - default_conf['trade_source'] = "file" default_conf['exportfilename'] = "testfile.json" - load_trades(default_conf) + load_trades("file", + db_url=default_conf.get('db_url'), + exportfilename=default_conf.get('exportfilename'),) assert db_mock.call_count == 0 assert bt_mock.call_count == 1