Add some initial tests for plot_dataframe

This commit is contained in:
Matthias 2019-08-22 16:21:48 +02:00
parent 69c2b12879
commit f8c72feea8
4 changed files with 25 additions and 11 deletions

View File

@ -34,10 +34,8 @@ ARGS_CREATE_USERDIR = ["user_data_dir"]
ARGS_DOWNLOAD_DATA = ["pairs", "pairs_file", "days", "exchange", "timeframes", "erase"] ARGS_DOWNLOAD_DATA = ["pairs", "pairs_file", "days", "exchange", "timeframes", "erase"]
ARGS_PLOT_DATAFRAME = (ARGS_COMMON + ARGS_STRATEGY + ARGS_PLOT_DATAFRAME = ["pairs", "indicators1", "indicators2", "plot_limit", "db_url",
["pairs", "indicators1", "indicators2", "plot_limit", "db_url", "trade_source", "export", "exportfilename", "timerange", "refresh_pairs"]
"trade_source", "export", "exportfilename", "timerange",
"refresh_pairs"])
ARGS_PLOT_PROFIT = (ARGS_COMMON + ARGS_STRATEGY + ARGS_PLOT_PROFIT = (ARGS_COMMON + ARGS_STRATEGY +
["pairs", "timerange", "export", "exportfilename", "db_url", "trade_source"]) ["pairs", "timerange", "export", "exportfilename", "db_url", "trade_source"])

View File

@ -6,7 +6,7 @@ from freqtrade.utils import setup_utils_configuration
def start_plot_dataframe(args: Namespace) -> None: def start_plot_dataframe(args: Namespace) -> None:
""" """
Plotting dataframe Plotting dataframe helper
""" """
# Import here to avoid errors if plot-dependencies are not installed. # Import here to avoid errors if plot-dependencies are not installed.
from freqtrade.plot.plotting import analyse_and_plot_pairs from freqtrade.plot.plotting import analyse_and_plot_pairs

View File

@ -328,11 +328,11 @@ def analyse_and_plot_pairs(config: Dict[str, Any]):
""" """
From configuration provided From configuration provided
- Initializes plot-script - Initializes plot-script
-Get tickers data - Get tickers data
-Generate Dafaframes populated with indicators and signals - Generate Dafaframes populated with indicators and signals based on configured strategy
-Load trades excecuted on same periods - Load trades excecuted during the selected period
-Generate Plotly plot objects - Generate Plotly plot objects
-Generate plot files - Generate plot files
:return: None :return: None
""" """
plot_elements = init_plotscript(config) plot_elements = init_plotscript(config)

View File

@ -9,13 +9,14 @@ from plotly.subplots import make_subplots
from freqtrade.configuration import TimeRange from freqtrade.configuration import TimeRange
from freqtrade.data import history from freqtrade.data import history
from freqtrade.data.btanalysis import create_cum_profit, load_backtest_data from freqtrade.data.btanalysis import create_cum_profit, load_backtest_data
from freqtrade.plot.plot_utils import start_plot_dataframe
from freqtrade.plot.plotting import (add_indicators, add_profit, from freqtrade.plot.plotting import (add_indicators, add_profit,
generate_candlestick_graph, generate_candlestick_graph,
generate_plot_filename, generate_plot_filename,
generate_profit_graph, init_plotscript, generate_profit_graph, init_plotscript,
plot_trades, store_plot_file) plot_trades, store_plot_file)
from freqtrade.strategy.default_strategy import DefaultStrategy from freqtrade.strategy.default_strategy import DefaultStrategy
from freqtrade.tests.conftest import log_has, log_has_re from freqtrade.tests.conftest import get_args, log_has, log_has_re
def fig_generating_mock(fig, *args, **kwargs): def fig_generating_mock(fig, *args, **kwargs):
@ -270,3 +271,18 @@ def test_generate_profit_graph():
for pair in pairs: for pair in pairs:
profit_pair = find_trace_in_fig_data(figure.data, f"Profit {pair}") profit_pair = find_trace_in_fig_data(figure.data, f"Profit {pair}")
assert isinstance(profit_pair, go.Scattergl) assert isinstance(profit_pair, go.Scattergl)
def test_start_plot_dataframe(mocker):
aup = mocker.patch("freqtrade.plot.plotting.analyse_and_plot_pairs", MagicMock())
args = [
"--config", "config.json.example",
"plot-dataframe",
"--pairs", "ETH/BTC"
]
start_plot_dataframe(get_args(args))
assert aup.call_count == 1
called_config = aup.call_args_list[0][0][0]
assert "pairs" in called_config
assert called_config['pairs'] == ["ETH/BTC"]