Fix if no file exists
This commit is contained in:
parent
5d1b1573b7
commit
27faf12fde
@ -59,7 +59,7 @@ ARGS_DOWNLOAD_DATA = ["pairs", "pairs_file", "days", "download_trades", "exchang
|
||||
|
||||
ARGS_PLOT_DATAFRAME = ["pairs", "indicators1", "indicators2", "plot_limit",
|
||||
"db_url", "trade_source", "export", "exportfilename",
|
||||
"timerange", "ticker_interval"]
|
||||
"timerange", "ticker_interval", "skip_trades"]
|
||||
|
||||
ARGS_PLOT_PROFIT = ["pairs", "timerange", "export", "exportfilename", "db_url",
|
||||
"trade_source", "ticker_interval"]
|
||||
|
@ -413,6 +413,11 @@ AVAILABLE_CLI_OPTIONS = {
|
||||
metavar='INT',
|
||||
default=750,
|
||||
),
|
||||
"skip_trades": Arg(
|
||||
'--skip-trades',
|
||||
help='Skip using trades file from backtesting and DB.',
|
||||
action='store_true',
|
||||
),
|
||||
"trade_source": Arg(
|
||||
'--trade-source',
|
||||
help='Specify the source for trades (Can be DB or file (backtest file)) '
|
||||
|
@ -129,12 +129,16 @@ def load_trades_from_db(db_url: str) -> pd.DataFrame:
|
||||
return trades
|
||||
|
||||
|
||||
def load_trades(source: str, db_url: str, exportfilename: str) -> pd.DataFrame:
|
||||
def load_trades(source: str, db_url: str, exportfilename: str, skip_trades: bool) -> pd.DataFrame:
|
||||
"""
|
||||
Based on configuration option "trade_source":
|
||||
* loads data from DB (using `db_url`)
|
||||
* loads data from backtestfile (using `exportfilename`)
|
||||
"""
|
||||
if skip_trades:
|
||||
df = pd.DataFrame(columns=BT_DATA_COLUMNS)
|
||||
return df
|
||||
|
||||
if source == "DB":
|
||||
return load_trades_from_db(db_url)
|
||||
elif source == "file":
|
||||
|
@ -3,6 +3,7 @@ from pathlib import Path
|
||||
from typing import Any, Dict, List
|
||||
|
||||
import pandas as pd
|
||||
from os.path import isfile
|
||||
|
||||
from freqtrade.configuration import TimeRange
|
||||
from freqtrade.data.btanalysis import (calculate_max_drawdown,
|
||||
@ -48,11 +49,21 @@ def init_plotscript(config):
|
||||
data_format=config.get('dataformat_ohlcv', 'json'),
|
||||
)
|
||||
|
||||
trades = load_trades(config['trade_source'],
|
||||
skip_trades = False
|
||||
if not isfile(config.get('exportfilename')) and config['trade_source'] == 'file':
|
||||
logger.info("Backtest file is missing skipping trades.")
|
||||
skip_trades = True
|
||||
elif config.get('skip_trades', False):
|
||||
skip_trades = True
|
||||
|
||||
trades = load_trades(
|
||||
config['trade_source'],
|
||||
db_url=config.get('db_url'),
|
||||
exportfilename=config.get('exportfilename'),
|
||||
skip_trades=skip_trades
|
||||
)
|
||||
trades = trim_dataframe(trades, timerange, 'open_time')
|
||||
|
||||
return {"ohlcv": data,
|
||||
"trades": trades,
|
||||
"pairs": pairs,
|
||||
|
@ -104,6 +104,7 @@ def test_load_trades(default_conf, mocker):
|
||||
load_trades("DB",
|
||||
db_url=default_conf.get('db_url'),
|
||||
exportfilename=default_conf.get('exportfilename'),
|
||||
skip_trades=False
|
||||
)
|
||||
|
||||
assert db_mock.call_count == 1
|
||||
@ -114,7 +115,9 @@ def test_load_trades(default_conf, mocker):
|
||||
default_conf['exportfilename'] = "testfile.json"
|
||||
load_trades("file",
|
||||
db_url=default_conf.get('db_url'),
|
||||
exportfilename=default_conf.get('exportfilename'),)
|
||||
exportfilename=default_conf.get('exportfilename'),
|
||||
skip_trades=False
|
||||
)
|
||||
|
||||
assert db_mock.call_count == 0
|
||||
assert bt_mock.call_count == 1
|
||||
|
Loading…
Reference in New Issue
Block a user