mirror of
https://github.com/freqtrade/freqtrade.git
synced 2026-01-20 05:50:36 +00:00
ruff format: Update a few test files
This commit is contained in:
@@ -31,7 +31,7 @@ from tests.conftest import get_args, log_has, log_has_re, patch_exchange
|
||||
|
||||
|
||||
def fig_generating_mock(fig, *args, **kwargs):
|
||||
""" Return Fig - used to mock add_indicators and plot_trades"""
|
||||
"""Return Fig - used to mock add_indicators and plot_trades"""
|
||||
return fig
|
||||
|
||||
|
||||
@@ -51,18 +51,18 @@ def generate_empty_figure():
|
||||
|
||||
|
||||
def test_init_plotscript(default_conf, mocker, testdatadir):
|
||||
default_conf['timerange'] = "20180110-20180112"
|
||||
default_conf['trade_source'] = "file"
|
||||
default_conf['timeframe'] = "5m"
|
||||
default_conf['exportfilename'] = testdatadir / "backtest-result.json"
|
||||
default_conf["timerange"] = "20180110-20180112"
|
||||
default_conf["trade_source"] = "file"
|
||||
default_conf["timeframe"] = "5m"
|
||||
default_conf["exportfilename"] = testdatadir / "backtest-result.json"
|
||||
supported_markets = ["TRX/BTC", "ADA/BTC"]
|
||||
ret = init_plotscript(default_conf, supported_markets)
|
||||
assert "ohlcv" in ret
|
||||
assert "trades" in ret
|
||||
assert "pairs" in ret
|
||||
assert 'timerange' in ret
|
||||
assert "timerange" in ret
|
||||
|
||||
default_conf['pairs'] = ["TRX/BTC", "ADA/BTC"]
|
||||
default_conf["pairs"] = ["TRX/BTC", "ADA/BTC"]
|
||||
ret = init_plotscript(default_conf, supported_markets, 20)
|
||||
assert "ohlcv" in ret
|
||||
assert "TRX/BTC" in ret["ohlcv"]
|
||||
@@ -73,15 +73,16 @@ def test_add_indicators(default_conf, testdatadir, caplog):
|
||||
pair = "UNITTEST/BTC"
|
||||
timerange = TimeRange()
|
||||
|
||||
data = history.load_pair_history(pair=pair, timeframe='1m',
|
||||
datadir=testdatadir, timerange=timerange)
|
||||
data = history.load_pair_history(
|
||||
pair=pair, timeframe="1m", datadir=testdatadir, timerange=timerange
|
||||
)
|
||||
indicators1 = {"ema10": {}}
|
||||
indicators2 = {"macd": {"color": "red"}}
|
||||
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
|
||||
# Generate entry/exit signals and indicators
|
||||
data = strategy.analyze_ticker(data, {'pair': pair})
|
||||
data = strategy.analyze_ticker(data, {"pair": pair})
|
||||
fig = generate_empty_figure()
|
||||
|
||||
# Row 1
|
||||
@@ -99,39 +100,43 @@ def test_add_indicators(default_conf, testdatadir, caplog):
|
||||
assert macd.line.color == "red"
|
||||
|
||||
# No indicator found
|
||||
fig3 = add_indicators(fig=deepcopy(fig), row=3, indicators={'no_indicator': {}}, data=data)
|
||||
fig3 = add_indicators(fig=deepcopy(fig), row=3, indicators={"no_indicator": {}}, data=data)
|
||||
assert fig == fig3
|
||||
assert log_has_re(r'Indicator "no_indicator" ignored\..*', caplog)
|
||||
|
||||
|
||||
def test_add_areas(default_conf, testdatadir, caplog):
|
||||
pair = "UNITTEST/BTC"
|
||||
timerange = TimeRange(None, 'line', 0, -1000)
|
||||
timerange = TimeRange(None, "line", 0, -1000)
|
||||
|
||||
data = history.load_pair_history(pair=pair, timeframe='1m',
|
||||
datadir=testdatadir, timerange=timerange)
|
||||
indicators = {"macd": {"color": "red",
|
||||
"fill_color": "black",
|
||||
"fill_to": "macdhist",
|
||||
"fill_label": "MACD Fill"}}
|
||||
data = history.load_pair_history(
|
||||
pair=pair, timeframe="1m", datadir=testdatadir, timerange=timerange
|
||||
)
|
||||
indicators = {
|
||||
"macd": {
|
||||
"color": "red",
|
||||
"fill_color": "black",
|
||||
"fill_to": "macdhist",
|
||||
"fill_label": "MACD Fill",
|
||||
}
|
||||
}
|
||||
|
||||
ind_no_label = {"macd": {"fill_color": "red",
|
||||
"fill_to": "macdhist"}}
|
||||
ind_no_label = {"macd": {"fill_color": "red", "fill_to": "macdhist"}}
|
||||
|
||||
ind_plain = {"macd": {"fill_to": "macdhist"}}
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
|
||||
# Generate entry/exit signals and indicators
|
||||
data = strategy.analyze_ticker(data, {'pair': pair})
|
||||
data = strategy.analyze_ticker(data, {"pair": pair})
|
||||
fig = generate_empty_figure()
|
||||
|
||||
# indicator mentioned in fill_to does not exist
|
||||
fig1 = add_areas(fig, 1, data, {'ema10': {'fill_to': 'no_fill_indicator'}})
|
||||
fig1 = add_areas(fig, 1, data, {"ema10": {"fill_to": "no_fill_indicator"}})
|
||||
assert fig == fig1
|
||||
assert log_has_re(r'fill_to: "no_fill_indicator" ignored\..*', caplog)
|
||||
|
||||
# indicator does not exist
|
||||
fig2 = add_areas(fig, 1, data, {'no_indicator': {'fill_to': 'ema10'}})
|
||||
fig2 = add_areas(fig, 1, data, {"no_indicator": {"fill_to": "ema10"}})
|
||||
assert fig == fig2
|
||||
assert log_has_re(r'Indicator "no_indicator" ignored\..*', caplog)
|
||||
|
||||
@@ -168,56 +173,60 @@ def test_plot_trades(testdatadir, caplog):
|
||||
pair = "ADA/BTC"
|
||||
filename = testdatadir / "backtest_results/backtest-result.json"
|
||||
trades = load_backtest_data(filename)
|
||||
trades = trades.loc[trades['pair'] == pair]
|
||||
trades = trades.loc[trades["pair"] == pair]
|
||||
|
||||
fig = plot_trades(fig, trades)
|
||||
figure = fig1.layout.figure
|
||||
|
||||
# Check entry - color, should be in first graph, ...
|
||||
trade_entries = find_trace_in_fig_data(figure.data, 'Trade entry')
|
||||
trade_entries = find_trace_in_fig_data(figure.data, "Trade entry")
|
||||
assert isinstance(trade_entries, go.Scatter)
|
||||
assert trade_entries.yaxis == 'y'
|
||||
assert trade_entries.yaxis == "y"
|
||||
assert len(trades) == len(trade_entries.x)
|
||||
assert trade_entries.marker.color == 'cyan'
|
||||
assert trade_entries.marker.symbol == 'circle-open'
|
||||
assert trade_entries.text[0] == '3.99%, buy_tag, roi, 15 min'
|
||||
assert trade_entries.marker.color == "cyan"
|
||||
assert trade_entries.marker.symbol == "circle-open"
|
||||
assert trade_entries.text[0] == "3.99%, buy_tag, roi, 15 min"
|
||||
|
||||
trade_exit = find_trace_in_fig_data(figure.data, 'Exit - Profit')
|
||||
trade_exit = find_trace_in_fig_data(figure.data, "Exit - Profit")
|
||||
assert isinstance(trade_exit, go.Scatter)
|
||||
assert trade_exit.yaxis == 'y'
|
||||
assert len(trades.loc[trades['profit_ratio'] > 0]) == len(trade_exit.x)
|
||||
assert trade_exit.marker.color == 'green'
|
||||
assert trade_exit.marker.symbol == 'square-open'
|
||||
assert trade_exit.text[0] == '3.99%, buy_tag, roi, 15 min'
|
||||
assert trade_exit.yaxis == "y"
|
||||
assert len(trades.loc[trades["profit_ratio"] > 0]) == len(trade_exit.x)
|
||||
assert trade_exit.marker.color == "green"
|
||||
assert trade_exit.marker.symbol == "square-open"
|
||||
assert trade_exit.text[0] == "3.99%, buy_tag, roi, 15 min"
|
||||
|
||||
trade_sell_loss = find_trace_in_fig_data(figure.data, 'Exit - Loss')
|
||||
trade_sell_loss = find_trace_in_fig_data(figure.data, "Exit - Loss")
|
||||
assert isinstance(trade_sell_loss, go.Scatter)
|
||||
assert trade_sell_loss.yaxis == 'y'
|
||||
assert len(trades.loc[trades['profit_ratio'] <= 0]) == len(trade_sell_loss.x)
|
||||
assert trade_sell_loss.marker.color == 'red'
|
||||
assert trade_sell_loss.marker.symbol == 'square-open'
|
||||
assert trade_sell_loss.text[5] == '-10.45%, stop_loss, 720 min'
|
||||
assert trade_sell_loss.yaxis == "y"
|
||||
assert len(trades.loc[trades["profit_ratio"] <= 0]) == len(trade_sell_loss.x)
|
||||
assert trade_sell_loss.marker.color == "red"
|
||||
assert trade_sell_loss.marker.symbol == "square-open"
|
||||
assert trade_sell_loss.text[5] == "-10.45%, stop_loss, 720 min"
|
||||
|
||||
|
||||
def test_generate_candlestick_graph_no_signals_no_trades(default_conf, mocker, testdatadir, caplog):
|
||||
row_mock = mocker.patch('freqtrade.plot.plotting.add_indicators',
|
||||
MagicMock(side_effect=fig_generating_mock))
|
||||
trades_mock = mocker.patch('freqtrade.plot.plotting.plot_trades',
|
||||
MagicMock(side_effect=fig_generating_mock))
|
||||
row_mock = mocker.patch(
|
||||
"freqtrade.plot.plotting.add_indicators", MagicMock(side_effect=fig_generating_mock)
|
||||
)
|
||||
trades_mock = mocker.patch(
|
||||
"freqtrade.plot.plotting.plot_trades", MagicMock(side_effect=fig_generating_mock)
|
||||
)
|
||||
|
||||
pair = "UNITTEST/BTC"
|
||||
timerange = TimeRange(None, 'line', 0, -1000)
|
||||
data = history.load_pair_history(pair=pair, timeframe='1m',
|
||||
datadir=testdatadir, timerange=timerange)
|
||||
data['enter_long'] = 0
|
||||
data['exit_long'] = 0
|
||||
data['enter_short'] = 0
|
||||
data['exit_short'] = 0
|
||||
timerange = TimeRange(None, "line", 0, -1000)
|
||||
data = history.load_pair_history(
|
||||
pair=pair, timeframe="1m", datadir=testdatadir, timerange=timerange
|
||||
)
|
||||
data["enter_long"] = 0
|
||||
data["exit_long"] = 0
|
||||
data["enter_short"] = 0
|
||||
data["exit_short"] = 0
|
||||
|
||||
indicators1 = []
|
||||
indicators2 = []
|
||||
fig = generate_candlestick_graph(pair=pair, data=data, trades=None,
|
||||
indicators1=indicators1, indicators2=indicators2)
|
||||
fig = generate_candlestick_graph(
|
||||
pair=pair, data=data, trades=None, indicators1=indicators1, indicators2=indicators2
|
||||
)
|
||||
assert isinstance(fig, go.Figure)
|
||||
assert fig.layout.title.text == pair
|
||||
figure = fig.layout.figure
|
||||
@@ -240,24 +249,28 @@ def test_generate_candlestick_graph_no_signals_no_trades(default_conf, mocker, t
|
||||
|
||||
|
||||
def test_generate_candlestick_graph_no_trades(default_conf, mocker, testdatadir):
|
||||
row_mock = mocker.patch('freqtrade.plot.plotting.add_indicators',
|
||||
MagicMock(side_effect=fig_generating_mock))
|
||||
trades_mock = mocker.patch('freqtrade.plot.plotting.plot_trades',
|
||||
MagicMock(side_effect=fig_generating_mock))
|
||||
pair = 'UNITTEST/BTC'
|
||||
timerange = TimeRange(None, 'line', 0, -1000)
|
||||
data = history.load_pair_history(pair=pair, timeframe='1m',
|
||||
datadir=testdatadir, timerange=timerange)
|
||||
row_mock = mocker.patch(
|
||||
"freqtrade.plot.plotting.add_indicators", MagicMock(side_effect=fig_generating_mock)
|
||||
)
|
||||
trades_mock = mocker.patch(
|
||||
"freqtrade.plot.plotting.plot_trades", MagicMock(side_effect=fig_generating_mock)
|
||||
)
|
||||
pair = "UNITTEST/BTC"
|
||||
timerange = TimeRange(None, "line", 0, -1000)
|
||||
data = history.load_pair_history(
|
||||
pair=pair, timeframe="1m", datadir=testdatadir, timerange=timerange
|
||||
)
|
||||
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
|
||||
# Generate buy/sell signals and indicators
|
||||
data = strategy.analyze_ticker(data, {'pair': pair})
|
||||
data = strategy.analyze_ticker(data, {"pair": pair})
|
||||
|
||||
indicators1 = []
|
||||
indicators2 = []
|
||||
fig = generate_candlestick_graph(pair=pair, data=data, trades=None,
|
||||
indicators1=indicators1, indicators2=indicators2)
|
||||
fig = generate_candlestick_graph(
|
||||
pair=pair, data=data, trades=None, indicators1=indicators1, indicators2=indicators2
|
||||
)
|
||||
assert isinstance(fig, go.Figure)
|
||||
assert fig.layout.title.text == pair
|
||||
figure = fig.layout.figure
|
||||
@@ -273,12 +286,12 @@ def test_generate_candlestick_graph_no_trades(default_conf, mocker, testdatadir)
|
||||
enter_long = find_trace_in_fig_data(figure.data, "enter_long")
|
||||
assert isinstance(enter_long, go.Scatter)
|
||||
# All buy-signals should be plotted
|
||||
assert int(data['enter_long'].sum()) == len(enter_long.x)
|
||||
assert int(data["enter_long"].sum()) == len(enter_long.x)
|
||||
|
||||
exit_long = find_trace_in_fig_data(figure.data, "exit_long")
|
||||
assert isinstance(exit_long, go.Scatter)
|
||||
# All buy-signals should be plotted
|
||||
assert int(data['exit_long'].sum()) == len(exit_long.x)
|
||||
assert int(data["exit_long"].sum()) == len(exit_long.x)
|
||||
|
||||
assert find_trace_in_fig_data(figure.data, "Bollinger Band")
|
||||
|
||||
@@ -294,16 +307,15 @@ def test_generate_Plot_filename():
|
||||
def test_generate_plot_file(mocker, caplog, user_dir):
|
||||
fig = generate_empty_figure()
|
||||
plot_mock = mocker.patch("freqtrade.plot.plotting.plot", MagicMock())
|
||||
store_plot_file(fig, filename="freqtrade-plot-UNITTEST_BTC-5m.html",
|
||||
directory=user_dir / "plot")
|
||||
store_plot_file(
|
||||
fig, filename="freqtrade-plot-UNITTEST_BTC-5m.html", directory=user_dir / "plot"
|
||||
)
|
||||
|
||||
expected_fn = str(user_dir / "plot/freqtrade-plot-UNITTEST_BTC-5m.html")
|
||||
assert plot_mock.call_count == 1
|
||||
assert plot_mock.call_args[0][0] == fig
|
||||
assert (plot_mock.call_args_list[0][1]['filename']
|
||||
== expected_fn)
|
||||
assert log_has(f"Stored plot as {expected_fn}",
|
||||
caplog)
|
||||
assert plot_mock.call_args_list[0][1]["filename"] == expected_fn
|
||||
assert log_has(f"Stored plot as {expected_fn}", caplog)
|
||||
|
||||
|
||||
def test_add_profit(testdatadir):
|
||||
@@ -311,15 +323,16 @@ def test_add_profit(testdatadir):
|
||||
bt_data = load_backtest_data(filename)
|
||||
timerange = TimeRange.parse_timerange("20180110-20180112")
|
||||
|
||||
df = history.load_pair_history(pair="TRX/BTC", timeframe='5m',
|
||||
datadir=testdatadir, timerange=timerange)
|
||||
df = history.load_pair_history(
|
||||
pair="TRX/BTC", timeframe="5m", datadir=testdatadir, timerange=timerange
|
||||
)
|
||||
fig = generate_empty_figure()
|
||||
|
||||
cum_profits = create_cum_profit(df.set_index('date'),
|
||||
bt_data[bt_data["pair"] == 'TRX/BTC'],
|
||||
"cum_profits", timeframe="5m")
|
||||
cum_profits = create_cum_profit(
|
||||
df.set_index("date"), bt_data[bt_data["pair"] == "TRX/BTC"], "cum_profits", timeframe="5m"
|
||||
)
|
||||
|
||||
fig1 = add_profit(fig, row=2, data=cum_profits, column='cum_profits', name='Profits')
|
||||
fig1 = add_profit(fig, row=2, data=cum_profits, column="cum_profits", name="Profits")
|
||||
figure = fig1.layout.figure
|
||||
profits = find_trace_in_fig_data(figure.data, "Profits")
|
||||
assert isinstance(profits, go.Scatter)
|
||||
@@ -331,22 +344,15 @@ def test_generate_profit_graph(testdatadir):
|
||||
trades = load_backtest_data(filename)
|
||||
timerange = TimeRange.parse_timerange("20180110-20180112")
|
||||
pairs = ["TRX/BTC", "XLM/BTC"]
|
||||
trades = trades[trades['close_date'] < pd.Timestamp('2018-01-12', tz='UTC')]
|
||||
trades = trades[trades["close_date"] < pd.Timestamp("2018-01-12", tz="UTC")]
|
||||
|
||||
data = history.load_data(datadir=testdatadir,
|
||||
pairs=pairs,
|
||||
timeframe='5m',
|
||||
timerange=timerange)
|
||||
data = history.load_data(datadir=testdatadir, pairs=pairs, timeframe="5m", timerange=timerange)
|
||||
|
||||
trades = trades[trades['pair'].isin(pairs)]
|
||||
trades = trades[trades["pair"].isin(pairs)]
|
||||
|
||||
fig = generate_profit_graph(
|
||||
pairs,
|
||||
data,
|
||||
trades,
|
||||
timeframe="5m",
|
||||
stake_currency='BTC',
|
||||
starting_balance=0)
|
||||
pairs, data, trades, timeframe="5m", stake_currency="BTC", starting_balance=0
|
||||
)
|
||||
assert isinstance(fig, go.Figure)
|
||||
|
||||
assert fig.layout.title.text == "Freqtrade Profit plot"
|
||||
@@ -379,40 +385,48 @@ def test_generate_profit_graph(testdatadir):
|
||||
|
||||
with pytest.raises(OperationalException, match=r"No trades found.*"):
|
||||
# Pair cannot be empty - so it's an empty dataframe.
|
||||
generate_profit_graph(pairs, data, trades.loc[trades['pair'].isnull()], timeframe="5m",
|
||||
stake_currency='BTC', starting_balance=0)
|
||||
generate_profit_graph(
|
||||
pairs,
|
||||
data,
|
||||
trades.loc[trades["pair"].isnull()],
|
||||
timeframe="5m",
|
||||
stake_currency="BTC",
|
||||
starting_balance=0,
|
||||
)
|
||||
|
||||
|
||||
def test_start_plot_dataframe(mocker):
|
||||
aup = mocker.patch("freqtrade.plot.plotting.load_and_plot_trades", MagicMock())
|
||||
args = [
|
||||
"plot-dataframe",
|
||||
"--config", "tests/testdata/testconfigs/main_test_config.json",
|
||||
"--pairs", "ETH/BTC"
|
||||
"--config",
|
||||
"tests/testdata/testconfigs/main_test_config.json",
|
||||
"--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"]
|
||||
assert called_config["pairs"] == ["ETH/BTC"]
|
||||
|
||||
|
||||
def test_load_and_plot_trades(default_conf, mocker, caplog, testdatadir):
|
||||
patch_exchange(mocker)
|
||||
|
||||
default_conf['trade_source'] = 'file'
|
||||
default_conf['exportfilename'] = testdatadir / "backtest-result.json"
|
||||
default_conf['indicators1'] = ["sma5", "ema10"]
|
||||
default_conf['indicators2'] = ["macd"]
|
||||
default_conf['pairs'] = ["ETH/BTC", "LTC/BTC"]
|
||||
default_conf["trade_source"] = "file"
|
||||
default_conf["exportfilename"] = testdatadir / "backtest-result.json"
|
||||
default_conf["indicators1"] = ["sma5", "ema10"]
|
||||
default_conf["indicators2"] = ["macd"]
|
||||
default_conf["pairs"] = ["ETH/BTC", "LTC/BTC"]
|
||||
|
||||
candle_mock = MagicMock()
|
||||
store_mock = MagicMock()
|
||||
mocker.patch.multiple(
|
||||
"freqtrade.plot.plotting",
|
||||
generate_candlestick_graph=candle_mock,
|
||||
store_plot_file=store_mock
|
||||
store_plot_file=store_mock,
|
||||
)
|
||||
load_and_plot_trades(default_conf)
|
||||
|
||||
@@ -420,8 +434,8 @@ def test_load_and_plot_trades(default_conf, mocker, caplog, testdatadir):
|
||||
assert candle_mock.call_count == 2
|
||||
assert store_mock.call_count == 2
|
||||
|
||||
assert candle_mock.call_args_list[0][1]['indicators1'] == ['sma5', 'ema10']
|
||||
assert candle_mock.call_args_list[0][1]['indicators2'] == ['macd']
|
||||
assert candle_mock.call_args_list[0][1]["indicators1"] == ["sma5", "ema10"]
|
||||
assert candle_mock.call_args_list[0][1]["indicators2"] == ["macd"]
|
||||
|
||||
assert log_has("End of plotting process. 2 plots generated", caplog)
|
||||
|
||||
@@ -430,49 +444,46 @@ def test_start_plot_profit(mocker):
|
||||
aup = mocker.patch("freqtrade.plot.plotting.plot_profit", MagicMock())
|
||||
args = [
|
||||
"plot-profit",
|
||||
"--config", "tests/testdata/testconfigs/main_test_config.json",
|
||||
"--pairs", "ETH/BTC"
|
||||
"--config",
|
||||
"tests/testdata/testconfigs/main_test_config.json",
|
||||
"--pairs",
|
||||
"ETH/BTC",
|
||||
]
|
||||
start_plot_profit(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"]
|
||||
assert called_config["pairs"] == ["ETH/BTC"]
|
||||
|
||||
|
||||
def test_start_plot_profit_error(mocker):
|
||||
|
||||
args = [
|
||||
'plot-profit',
|
||||
'--pairs', 'ETH/BTC'
|
||||
]
|
||||
args = ["plot-profit", "--pairs", "ETH/BTC"]
|
||||
argsp = get_args(args)
|
||||
# Make sure we use no config. Details: #2241
|
||||
# not resetting config causes random failures if config.json exists
|
||||
argsp['config'] = []
|
||||
argsp["config"] = []
|
||||
with pytest.raises(OperationalException):
|
||||
start_plot_profit(argsp)
|
||||
|
||||
|
||||
def test_plot_profit(default_conf, mocker, testdatadir):
|
||||
patch_exchange(mocker)
|
||||
default_conf['trade_source'] = 'file'
|
||||
default_conf['exportfilename'] = testdatadir / 'backtest-result_test_nofile.json'
|
||||
default_conf['pairs'] = ['ETH/BTC', 'LTC/BTC']
|
||||
default_conf["trade_source"] = "file"
|
||||
default_conf["exportfilename"] = testdatadir / "backtest-result_test_nofile.json"
|
||||
default_conf["pairs"] = ["ETH/BTC", "LTC/BTC"]
|
||||
|
||||
profit_mock = MagicMock()
|
||||
store_mock = MagicMock()
|
||||
mocker.patch.multiple(
|
||||
"freqtrade.plot.plotting",
|
||||
generate_profit_graph=profit_mock,
|
||||
store_plot_file=store_mock
|
||||
"freqtrade.plot.plotting", generate_profit_graph=profit_mock, store_plot_file=store_mock
|
||||
)
|
||||
with pytest.raises(OperationalException,
|
||||
match=r"No trades found, cannot generate Profit-plot.*"):
|
||||
with pytest.raises(
|
||||
OperationalException, match=r"No trades found, cannot generate Profit-plot.*"
|
||||
):
|
||||
plot_profit(default_conf)
|
||||
|
||||
default_conf['exportfilename'] = testdatadir / "backtest_results/backtest-result.json"
|
||||
default_conf["exportfilename"] = testdatadir / "backtest_results/backtest-result.json"
|
||||
|
||||
plot_profit(default_conf)
|
||||
|
||||
@@ -480,53 +491,78 @@ def test_plot_profit(default_conf, mocker, testdatadir):
|
||||
assert profit_mock.call_count == 1
|
||||
assert store_mock.call_count == 1
|
||||
|
||||
assert profit_mock.call_args_list[0][0][0] == default_conf['pairs']
|
||||
assert store_mock.call_args_list[0][1]['auto_open'] is False
|
||||
assert profit_mock.call_args_list[0][0][0] == default_conf["pairs"]
|
||||
assert store_mock.call_args_list[0][1]["auto_open"] is False
|
||||
|
||||
del default_conf['timeframe']
|
||||
del default_conf["timeframe"]
|
||||
with pytest.raises(OperationalException, match=r"Timeframe must be set.*--timeframe.*"):
|
||||
plot_profit(default_conf)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("ind1,ind2,plot_conf,exp", [
|
||||
# No indicators, use plot_conf
|
||||
([], [], {},
|
||||
{'main_plot': {'sma': {}, 'ema3': {}, 'ema5': {}},
|
||||
'subplots': {'Other': {'macd': {}, 'macdsignal': {}}}}),
|
||||
# use indicators
|
||||
(['sma', 'ema3'], ['macd'], {},
|
||||
{'main_plot': {'sma': {}, 'ema3': {}}, 'subplots': {'Other': {'macd': {}}}}),
|
||||
# only main_plot - adds empty subplots
|
||||
([], [], {'main_plot': {'sma': {}}},
|
||||
{'main_plot': {'sma': {}}, 'subplots': {}}),
|
||||
# Main and subplots
|
||||
([], [], {'main_plot': {'sma': {}}, 'subplots': {'RSI': {'rsi': {'color': 'red'}}}},
|
||||
{'main_plot': {'sma': {}}, 'subplots': {'RSI': {'rsi': {'color': 'red'}}}}),
|
||||
# no main_plot, adds empty main_plot
|
||||
([], [], {'subplots': {'RSI': {'rsi': {'color': 'red'}}}},
|
||||
{'main_plot': {}, 'subplots': {'RSI': {'rsi': {'color': 'red'}}}}),
|
||||
# indicator 1 / 2 should have prevalence
|
||||
(['sma', 'ema3'], ['macd'],
|
||||
{'main_plot': {'sma': {}}, 'subplots': {'RSI': {'rsi': {'color': 'red'}}}},
|
||||
{'main_plot': {'sma': {}, 'ema3': {}}, 'subplots': {'Other': {'macd': {}}}}
|
||||
),
|
||||
# indicator 1 - overrides plot_config main_plot
|
||||
(['sma', 'ema3'], [],
|
||||
{'main_plot': {'sma': {}}, 'subplots': {'RSI': {'rsi': {'color': 'red'}}}},
|
||||
{'main_plot': {'sma': {}, 'ema3': {}}, 'subplots': {'RSI': {'rsi': {'color': 'red'}}}}
|
||||
),
|
||||
# indicator 2 - overrides plot_config subplots
|
||||
([], ['macd', 'macd_signal'],
|
||||
{'main_plot': {'sma': {}}, 'subplots': {'RSI': {'rsi': {'color': 'red'}}}},
|
||||
{'main_plot': {'sma': {}}, 'subplots': {'Other': {'macd': {}, 'macd_signal': {}}}}
|
||||
),
|
||||
])
|
||||
@pytest.mark.parametrize(
|
||||
"ind1,ind2,plot_conf,exp",
|
||||
[
|
||||
# No indicators, use plot_conf
|
||||
(
|
||||
[],
|
||||
[],
|
||||
{},
|
||||
{
|
||||
"main_plot": {"sma": {}, "ema3": {}, "ema5": {}},
|
||||
"subplots": {"Other": {"macd": {}, "macdsignal": {}}},
|
||||
},
|
||||
),
|
||||
# use indicators
|
||||
(
|
||||
["sma", "ema3"],
|
||||
["macd"],
|
||||
{},
|
||||
{"main_plot": {"sma": {}, "ema3": {}}, "subplots": {"Other": {"macd": {}}}},
|
||||
),
|
||||
# only main_plot - adds empty subplots
|
||||
([], [], {"main_plot": {"sma": {}}}, {"main_plot": {"sma": {}}, "subplots": {}}),
|
||||
# Main and subplots
|
||||
(
|
||||
[],
|
||||
[],
|
||||
{"main_plot": {"sma": {}}, "subplots": {"RSI": {"rsi": {"color": "red"}}}},
|
||||
{"main_plot": {"sma": {}}, "subplots": {"RSI": {"rsi": {"color": "red"}}}},
|
||||
),
|
||||
# no main_plot, adds empty main_plot
|
||||
(
|
||||
[],
|
||||
[],
|
||||
{"subplots": {"RSI": {"rsi": {"color": "red"}}}},
|
||||
{"main_plot": {}, "subplots": {"RSI": {"rsi": {"color": "red"}}}},
|
||||
),
|
||||
# indicator 1 / 2 should have prevalence
|
||||
(
|
||||
["sma", "ema3"],
|
||||
["macd"],
|
||||
{"main_plot": {"sma": {}}, "subplots": {"RSI": {"rsi": {"color": "red"}}}},
|
||||
{"main_plot": {"sma": {}, "ema3": {}}, "subplots": {"Other": {"macd": {}}}},
|
||||
),
|
||||
# indicator 1 - overrides plot_config main_plot
|
||||
(
|
||||
["sma", "ema3"],
|
||||
[],
|
||||
{"main_plot": {"sma": {}}, "subplots": {"RSI": {"rsi": {"color": "red"}}}},
|
||||
{"main_plot": {"sma": {}, "ema3": {}}, "subplots": {"RSI": {"rsi": {"color": "red"}}}},
|
||||
),
|
||||
# indicator 2 - overrides plot_config subplots
|
||||
(
|
||||
[],
|
||||
["macd", "macd_signal"],
|
||||
{"main_plot": {"sma": {}}, "subplots": {"RSI": {"rsi": {"color": "red"}}}},
|
||||
{"main_plot": {"sma": {}}, "subplots": {"Other": {"macd": {}, "macd_signal": {}}}},
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_create_plotconfig(ind1, ind2, plot_conf, exp):
|
||||
|
||||
res = create_plotconfig(ind1, ind2, plot_conf)
|
||||
assert 'main_plot' in res
|
||||
assert 'subplots' in res
|
||||
assert isinstance(res['main_plot'], dict)
|
||||
assert isinstance(res['subplots'], dict)
|
||||
assert "main_plot" in res
|
||||
assert "subplots" in res
|
||||
assert isinstance(res["main_plot"], dict)
|
||||
assert isinstance(res["subplots"], dict)
|
||||
|
||||
assert res == exp
|
||||
|
||||
Reference in New Issue
Block a user