def test_plot_trades(caplog): fig1 = generage_empty_figure() # nothing happens when no trades are available fig = plot_trades(fig1, None) assert fig == fig1 assert log_has("No trades found.", caplog.record_tuples) pair = "ADA/BTC" filename = history.make_testdata_path(None) / "backtest-result_test.json" trades = load_backtest_data(filename) trades = trades.loc[trades['pair'] == pair] fig = plot_trades(fig, trades) figure = fig1.layout.figure # Check buys - color, should be in first graph, ... trade_buy = find_trace_in_fig_data(figure.data, "trade_buy") assert isinstance(trade_buy, go.Scatter) assert trade_buy.yaxis == 'y' assert len(trades) == len(trade_buy.x) assert trade_buy.marker.color == 'green' trade_sell = find_trace_in_fig_data(figure.data, "trade_sell") assert isinstance(trade_sell, go.Scatter) assert trade_sell.yaxis == 'y' assert len(trades) == len(trade_sell.x) assert trade_sell.marker.color == 'red'
def test_plot_trades(testdatadir, caplog): fig1 = generate_empty_figure() # nothing happens when no trades are available fig = plot_trades(fig1, None) assert fig == fig1 assert log_has("No trades found.", caplog) pair = "ADA/BTC" filename = testdatadir / "backtest-result_test.json" trades = load_backtest_data(filename) trades = trades.loc[trades['pair'] == pair] fig = plot_trades(fig, trades) figure = fig1.layout.figure # Check buys - color, should be in first graph, ... trade_buy = find_trace_in_fig_data(figure.data, 'Trade buy') assert isinstance(trade_buy, go.Scatter) assert trade_buy.yaxis == 'y' assert len(trades) == len(trade_buy.x) assert trade_buy.marker.color == 'cyan' assert trade_buy.marker.symbol == 'circle-open' assert trade_buy.text[0] == '4.0%, roi, 15 min' trade_sell = find_trace_in_fig_data(figure.data, 'Sell - Profit') assert isinstance(trade_sell, go.Scatter) assert trade_sell.yaxis == 'y' assert len(trades.loc[trades['profit_percent'] > 0]) == len(trade_sell.x) assert trade_sell.marker.color == 'green' assert trade_sell.marker.symbol == 'square-open' assert trade_sell.text[0] == '4.0%, roi, 15 min' trade_sell_loss = find_trace_in_fig_data(figure.data, 'Sell - Loss') assert isinstance(trade_sell_loss, go.Scatter) assert trade_sell_loss.yaxis == 'y' assert len(trades.loc[trades['profit_percent'] <= 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.4%, stop_loss, 720 min'