simplify load_trades call
This commit is contained in:
parent
1b374fcf7e
commit
545e5c5bc6
@ -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:
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user