Merge pull request #3062 from Fredrik81/plot-trades
Plotting: Fix if no file exists and new skip option
This commit is contained in:
commit
ac6eef6922
@ -23,44 +23,64 @@ The `freqtrade plot-dataframe` subcommand shows an interactive graph with three
|
|||||||
Possible arguments:
|
Possible arguments:
|
||||||
|
|
||||||
```
|
```
|
||||||
usage: freqtrade plot-dataframe [-h] [-v] [--logfile FILE] [-V] [-c PATH] [-d PATH] [--userdir PATH] [-s NAME]
|
usage: freqtrade plot-dataframe [-h] [-v] [--logfile FILE] [-V] [-c PATH]
|
||||||
[--strategy-path PATH] [-p PAIRS [PAIRS ...]] [--indicators1 INDICATORS1 [INDICATORS1 ...]]
|
[-d PATH] [--userdir PATH] [-s NAME]
|
||||||
[--indicators2 INDICATORS2 [INDICATORS2 ...]] [--plot-limit INT] [--db-url PATH]
|
[--strategy-path PATH] [-p PAIRS [PAIRS ...]]
|
||||||
[--trade-source {DB,file}] [--export EXPORT] [--export-filename PATH] [--timerange TIMERANGE]
|
[--indicators1 INDICATORS1 [INDICATORS1 ...]]
|
||||||
[-i TICKER_INTERVAL]
|
[--indicators2 INDICATORS2 [INDICATORS2 ...]]
|
||||||
|
[--plot-limit INT] [--db-url PATH]
|
||||||
|
[--trade-source {DB,file}] [--export EXPORT]
|
||||||
|
[--export-filename PATH]
|
||||||
|
[--timerange TIMERANGE] [-i TICKER_INTERVAL]
|
||||||
|
[--no-trades]
|
||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]
|
-p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]
|
||||||
Show profits for only these pairs. Pairs are space-separated.
|
Show profits for only these pairs. Pairs are space-
|
||||||
|
separated.
|
||||||
--indicators1 INDICATORS1 [INDICATORS1 ...]
|
--indicators1 INDICATORS1 [INDICATORS1 ...]
|
||||||
Set indicators from your strategy you want in the first row of the graph. Space-separated list. Example:
|
Set indicators from your strategy you want in the
|
||||||
|
first row of the graph. Space-separated list. Example:
|
||||||
`ema3 ema5`. Default: `['sma', 'ema3', 'ema5']`.
|
`ema3 ema5`. Default: `['sma', 'ema3', 'ema5']`.
|
||||||
--indicators2 INDICATORS2 [INDICATORS2 ...]
|
--indicators2 INDICATORS2 [INDICATORS2 ...]
|
||||||
Set indicators from your strategy you want in the third row of the graph. Space-separated list. Example:
|
Set indicators from your strategy you want in the
|
||||||
|
third row of the graph. Space-separated list. Example:
|
||||||
`fastd fastk`. Default: `['macd', 'macdsignal']`.
|
`fastd fastk`. Default: `['macd', 'macdsignal']`.
|
||||||
--plot-limit INT Specify tick limit for plotting. Notice: too high values cause huge files. Default: 750.
|
--plot-limit INT Specify tick limit for plotting. Notice: too high
|
||||||
--db-url PATH Override trades database URL, this is useful in custom deployments (default: `sqlite:///tradesv3.sqlite`
|
values cause huge files. Default: 750.
|
||||||
for Live Run mode, `sqlite:///tradesv3.dryrun.sqlite` for Dry Run).
|
--db-url PATH Override trades database URL, this is useful in custom
|
||||||
|
deployments (default: `sqlite:///tradesv3.sqlite` for
|
||||||
|
Live Run mode, `sqlite:///tradesv3.dryrun.sqlite` for
|
||||||
|
Dry Run).
|
||||||
--trade-source {DB,file}
|
--trade-source {DB,file}
|
||||||
Specify the source for trades (Can be DB or file (backtest file)) Default: file
|
Specify the source for trades (Can be DB or file
|
||||||
--export EXPORT Export backtest results, argument are: trades. Example: `--export=trades`
|
(backtest file)) Default: file
|
||||||
|
--export EXPORT Export backtest results, argument are: trades.
|
||||||
|
Example: `--export=trades`
|
||||||
--export-filename PATH
|
--export-filename PATH
|
||||||
Save backtest results to the file with this filename. Requires `--export` to be set as well. Example:
|
Save backtest results to the file with this filename.
|
||||||
`--export-filename=user_data/backtest_results/backtest_today.json`
|
Requires `--export` to be set as well. Example:
|
||||||
|
`--export-filename=user_data/backtest_results/backtest
|
||||||
|
_today.json`
|
||||||
--timerange TIMERANGE
|
--timerange TIMERANGE
|
||||||
Specify what timerange of data to use.
|
Specify what timerange of data to use.
|
||||||
-i TICKER_INTERVAL, --ticker-interval TICKER_INTERVAL
|
-i TICKER_INTERVAL, --ticker-interval TICKER_INTERVAL
|
||||||
Specify ticker interval (`1m`, `5m`, `30m`, `1h`, `1d`).
|
Specify ticker interval (`1m`, `5m`, `30m`, `1h`,
|
||||||
|
`1d`).
|
||||||
|
--no-trades Skip using trades from backtesting file and DB.
|
||||||
|
|
||||||
Common arguments:
|
Common arguments:
|
||||||
-v, --verbose Verbose mode (-vv for more, -vvv to get all messages).
|
-v, --verbose Verbose mode (-vv for more, -vvv to get all messages).
|
||||||
--logfile FILE Log to the file specified. Special values are: 'syslog', 'journald'. See the documentation for more
|
--logfile FILE Log to the file specified. Special values are:
|
||||||
|
'syslog', 'journald'. See the documentation for more
|
||||||
details.
|
details.
|
||||||
-V, --version show program's version number and exit
|
-V, --version show program's version number and exit
|
||||||
-c PATH, --config PATH
|
-c PATH, --config PATH
|
||||||
Specify configuration file (default: `config.json`). Multiple --config options may be used. Can be set to
|
Specify configuration file (default:
|
||||||
`-` to read config from stdin.
|
`userdir/config.json` or `config.json` whichever
|
||||||
|
exists). Multiple --config options may be used. Can be
|
||||||
|
set to `-` to read config from stdin.
|
||||||
-d PATH, --datadir PATH
|
-d PATH, --datadir PATH
|
||||||
Path to directory with historical backtesting data.
|
Path to directory with historical backtesting data.
|
||||||
--userdir PATH, --user-data-dir PATH
|
--userdir PATH, --user-data-dir PATH
|
||||||
@ -68,9 +88,9 @@ Common arguments:
|
|||||||
|
|
||||||
Strategy arguments:
|
Strategy arguments:
|
||||||
-s NAME, --strategy NAME
|
-s NAME, --strategy NAME
|
||||||
Specify strategy class name which will be used by the bot.
|
Specify strategy class name which will be used by the
|
||||||
|
bot.
|
||||||
--strategy-path PATH Specify additional strategy lookup path.
|
--strategy-path PATH Specify additional strategy lookup path.
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
@ -59,7 +59,7 @@ ARGS_DOWNLOAD_DATA = ["pairs", "pairs_file", "days", "download_trades", "exchang
|
|||||||
|
|
||||||
ARGS_PLOT_DATAFRAME = ["pairs", "indicators1", "indicators2", "plot_limit",
|
ARGS_PLOT_DATAFRAME = ["pairs", "indicators1", "indicators2", "plot_limit",
|
||||||
"db_url", "trade_source", "export", "exportfilename",
|
"db_url", "trade_source", "export", "exportfilename",
|
||||||
"timerange", "ticker_interval"]
|
"timerange", "ticker_interval", "no_trades"]
|
||||||
|
|
||||||
ARGS_PLOT_PROFIT = ["pairs", "timerange", "export", "exportfilename", "db_url",
|
ARGS_PLOT_PROFIT = ["pairs", "timerange", "export", "exportfilename", "db_url",
|
||||||
"trade_source", "ticker_interval"]
|
"trade_source", "ticker_interval"]
|
||||||
|
@ -413,6 +413,11 @@ AVAILABLE_CLI_OPTIONS = {
|
|||||||
metavar='INT',
|
metavar='INT',
|
||||||
default=750,
|
default=750,
|
||||||
),
|
),
|
||||||
|
"no_trades": Arg(
|
||||||
|
'--no-trades',
|
||||||
|
help='Skip using trades from backtesting file and DB.',
|
||||||
|
action='store_true',
|
||||||
|
),
|
||||||
"trade_source": Arg(
|
"trade_source": Arg(
|
||||||
'--trade-source',
|
'--trade-source',
|
||||||
help='Specify the source for trades (Can be DB or file (backtest file)) '
|
help='Specify the source for trades (Can be DB or file (backtest file)) '
|
||||||
|
@ -359,6 +359,9 @@ class Configuration:
|
|||||||
self._args_to_config(config, argname='erase',
|
self._args_to_config(config, argname='erase',
|
||||||
logstring='Erase detected. Deleting existing data.')
|
logstring='Erase detected. Deleting existing data.')
|
||||||
|
|
||||||
|
self._args_to_config(config, argname='no_trades',
|
||||||
|
logstring='Parameter --no-trades detected.')
|
||||||
|
|
||||||
self._args_to_config(config, argname='timeframes',
|
self._args_to_config(config, argname='timeframes',
|
||||||
logstring='timeframes --timeframes: {}')
|
logstring='timeframes --timeframes: {}')
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ def load_trades_from_db(db_url: str) -> pd.DataFrame:
|
|||||||
t.calc_profit(), t.calc_profit_ratio(),
|
t.calc_profit(), t.calc_profit_ratio(),
|
||||||
t.open_rate, t.close_rate, t.amount,
|
t.open_rate, t.close_rate, t.amount,
|
||||||
(round((t.close_date.timestamp() - t.open_date.timestamp()) / 60, 2)
|
(round((t.close_date.timestamp() - t.open_date.timestamp()) / 60, 2)
|
||||||
if t.close_date else None),
|
if t.close_date else None),
|
||||||
t.sell_reason,
|
t.sell_reason,
|
||||||
t.fee_open, t.fee_close,
|
t.fee_open, t.fee_close,
|
||||||
t.open_rate_requested,
|
t.open_rate_requested,
|
||||||
@ -129,7 +129,8 @@ def load_trades_from_db(db_url: str) -> pd.DataFrame:
|
|||||||
return trades
|
return trades
|
||||||
|
|
||||||
|
|
||||||
def load_trades(source: str, db_url: str, exportfilename: Path) -> pd.DataFrame:
|
def load_trades(source: str, db_url: str, exportfilename: Path,
|
||||||
|
no_trades: bool = False) -> pd.DataFrame:
|
||||||
"""
|
"""
|
||||||
Based on configuration option "trade_source":
|
Based on configuration option "trade_source":
|
||||||
* loads data from DB (using `db_url`)
|
* loads data from DB (using `db_url`)
|
||||||
@ -137,8 +138,13 @@ def load_trades(source: str, db_url: str, exportfilename: Path) -> pd.DataFrame:
|
|||||||
:param source: "DB" or "file" - specify source to load from
|
:param source: "DB" or "file" - specify source to load from
|
||||||
:param db_url: sqlalchemy formatted url to a database
|
:param db_url: sqlalchemy formatted url to a database
|
||||||
:param exportfilename: Json file generated by backtesting
|
:param exportfilename: Json file generated by backtesting
|
||||||
|
:param no_trades: Skip using trades, only return backtesting data columns
|
||||||
:return: DataFrame containing trades
|
:return: DataFrame containing trades
|
||||||
"""
|
"""
|
||||||
|
if no_trades:
|
||||||
|
df = pd.DataFrame(columns=BT_DATA_COLUMNS)
|
||||||
|
return df
|
||||||
|
|
||||||
if source == "DB":
|
if source == "DB":
|
||||||
return load_trades_from_db(db_url)
|
return load_trades_from_db(db_url)
|
||||||
elif source == "file":
|
elif source == "file":
|
||||||
|
@ -48,11 +48,21 @@ def init_plotscript(config):
|
|||||||
data_format=config.get('dataformat_ohlcv', 'json'),
|
data_format=config.get('dataformat_ohlcv', 'json'),
|
||||||
)
|
)
|
||||||
|
|
||||||
trades = load_trades(config['trade_source'],
|
no_trades = False
|
||||||
db_url=config.get('db_url'),
|
if config.get('no_trades', False):
|
||||||
exportfilename=config.get('exportfilename'),
|
no_trades = True
|
||||||
)
|
elif not config['exportfilename'].is_file() and config['trade_source'] == 'file':
|
||||||
|
logger.warning("Backtest file is missing skipping trades.")
|
||||||
|
no_trades = True
|
||||||
|
|
||||||
|
trades = load_trades(
|
||||||
|
config['trade_source'],
|
||||||
|
db_url=config.get('db_url'),
|
||||||
|
exportfilename=config.get('exportfilename'),
|
||||||
|
no_trades=no_trades
|
||||||
|
)
|
||||||
trades = trim_dataframe(trades, timerange, 'open_time')
|
trades = trim_dataframe(trades, timerange, 'open_time')
|
||||||
|
|
||||||
return {"ohlcv": data,
|
return {"ohlcv": data,
|
||||||
"trades": trades,
|
"trades": trades,
|
||||||
"pairs": pairs,
|
"pairs": pairs,
|
||||||
|
@ -105,6 +105,7 @@ def test_load_trades(default_conf, mocker):
|
|||||||
load_trades("DB",
|
load_trades("DB",
|
||||||
db_url=default_conf.get('db_url'),
|
db_url=default_conf.get('db_url'),
|
||||||
exportfilename=default_conf.get('exportfilename'),
|
exportfilename=default_conf.get('exportfilename'),
|
||||||
|
no_trades=False
|
||||||
)
|
)
|
||||||
|
|
||||||
assert db_mock.call_count == 1
|
assert db_mock.call_count == 1
|
||||||
@ -115,11 +116,24 @@ def test_load_trades(default_conf, mocker):
|
|||||||
default_conf['exportfilename'] = Path("testfile.json")
|
default_conf['exportfilename'] = Path("testfile.json")
|
||||||
load_trades("file",
|
load_trades("file",
|
||||||
db_url=default_conf.get('db_url'),
|
db_url=default_conf.get('db_url'),
|
||||||
exportfilename=default_conf.get('exportfilename'),)
|
exportfilename=default_conf.get('exportfilename'),
|
||||||
|
)
|
||||||
|
|
||||||
assert db_mock.call_count == 0
|
assert db_mock.call_count == 0
|
||||||
assert bt_mock.call_count == 1
|
assert bt_mock.call_count == 1
|
||||||
|
|
||||||
|
db_mock.reset_mock()
|
||||||
|
bt_mock.reset_mock()
|
||||||
|
default_conf['exportfilename'] = "testfile.json"
|
||||||
|
load_trades("file",
|
||||||
|
db_url=default_conf.get('db_url'),
|
||||||
|
exportfilename=default_conf.get('exportfilename'),
|
||||||
|
no_trades=True
|
||||||
|
)
|
||||||
|
|
||||||
|
assert db_mock.call_count == 0
|
||||||
|
assert bt_mock.call_count == 0
|
||||||
|
|
||||||
|
|
||||||
def test_combine_dataframes_with_mean(testdatadir):
|
def test_combine_dataframes_with_mean(testdatadir):
|
||||||
pairs = ["ETH/BTC", "ADA/BTC"]
|
pairs = ["ETH/BTC", "ADA/BTC"]
|
||||||
|
Loading…
Reference in New Issue
Block a user