mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 02:12:01 +00:00
Seperate plot-name generation and plotting
This commit is contained in:
parent
4506832925
commit
e50eee59cf
|
@ -204,7 +204,16 @@ def generate_candlestick_graph(
|
|||
return fig
|
||||
|
||||
|
||||
def generate_plot_file(fig, pair, ticker_interval) -> None:
|
||||
def generate_plot_filename(pair, ticker_interval) -> str:
|
||||
pair_name = pair.replace("/", "_")
|
||||
file_name = 'freqtrade-plot-' + pair_name + '-' + ticker_interval + '.html'
|
||||
|
||||
logger.info('Generate plot file for %s', pair)
|
||||
|
||||
return file_name
|
||||
|
||||
|
||||
def generate_plot_file(fig, filename: str, auto_open: bool = False) -> None:
|
||||
"""
|
||||
Generate a plot html file from pre populated fig plotly object
|
||||
:param fig: Plotly Figure to plot
|
||||
|
@ -212,12 +221,8 @@ def generate_plot_file(fig, pair, ticker_interval) -> None:
|
|||
:param ticker_interval: Used as part of the filename
|
||||
:return: None
|
||||
"""
|
||||
logger.info('Generate plot file for %s', pair)
|
||||
|
||||
pair_name = pair.replace("/", "_")
|
||||
file_name = 'freqtrade-plot-' + pair_name + '-' + ticker_interval + '.html'
|
||||
|
||||
Path("user_data/plots").mkdir(parents=True, exist_ok=True)
|
||||
|
||||
plot(fig, filename=str(Path('user_data/plots').joinpath(file_name)),
|
||||
auto_open=False)
|
||||
plot(fig, filename=str(Path('user_data/plots').joinpath(filename)),
|
||||
auto_open=auto_open)
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
|
||||
from copy import deepcopy
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from plotly import tools
|
||||
import plotly.graph_objs as go
|
||||
from copy import deepcopy
|
||||
from plotly import tools
|
||||
|
||||
from freqtrade.arguments import TimeRange
|
||||
from freqtrade.data import history
|
||||
from freqtrade.data.btanalysis import load_backtest_data
|
||||
from freqtrade.plot.plotting import (generate_candlestick_graph, generate_plot_file,
|
||||
generate_row, plot_trades)
|
||||
from freqtrade.plot.plotting import (generate_candlestick_graph,
|
||||
generate_plot_file,
|
||||
generate_plot_filename, generate_row,
|
||||
plot_trades)
|
||||
from freqtrade.strategy.default_strategy import DefaultStrategy
|
||||
from freqtrade.tests.conftest import log_has, log_has_re
|
||||
|
||||
|
@ -178,10 +180,15 @@ def test_generate_candlestick_graph_no_trades(default_conf, mocker):
|
|||
assert trades_mock.call_count == 1
|
||||
|
||||
|
||||
def test_generate_Plot_filename():
|
||||
fn = generate_plot_filename("UNITTEST/BTC", "5m")
|
||||
assert fn == "freqtrade-plot-UNITTEST_BTC-5m.html"
|
||||
|
||||
|
||||
def test_generate_plot_file(mocker, caplog):
|
||||
fig = generage_empty_figure()
|
||||
plot_mock = mocker.patch("freqtrade.plot.plotting.plot", MagicMock())
|
||||
generate_plot_file(fig, "UNITTEST/BTC", "5m")
|
||||
generate_plot_file(fig, filename="freqtrade-plot-UNITTEST_BTC-5m.html")
|
||||
|
||||
assert plot_mock.call_count == 1
|
||||
assert plot_mock.call_args[0][0] == fig
|
||||
|
|
|
@ -24,7 +24,9 @@ from freqtrade.data import history
|
|||
from freqtrade.data.btanalysis import (extract_trades_of_period,
|
||||
load_backtest_data, load_trades_from_db)
|
||||
from freqtrade.optimize import setup_configuration
|
||||
from freqtrade.plot.plotting import generate_candlestick_graph, generate_plot_file
|
||||
from freqtrade.plot.plotting import (generate_candlestick_graph,
|
||||
generate_plot_file,
|
||||
generate_plot_filename)
|
||||
from freqtrade.resolvers import ExchangeResolver, StrategyResolver
|
||||
from freqtrade.state import RunMode
|
||||
|
||||
|
@ -101,7 +103,7 @@ def analyse_and_plot_pairs(config: Dict[str, Any]):
|
|||
indicators2=config["indicators2"].split(",")
|
||||
)
|
||||
|
||||
generate_plot_file(fig, pair, ticker_interval)
|
||||
generate_plot_file(fig, generate_plot_filename(pair, ticker_interval))
|
||||
|
||||
logger.info('End of ploting process %s plots generated', pair_counter)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user