better Path usage, remove arg parameter in generate_graph
This commit is contained in:
parent
22e7ad8ec1
commit
422a0ce114
@ -76,7 +76,7 @@ def load_trades(args: Namespace, pair: str, timerange: TimeRange) -> pd.DataFram
|
||||
# must align with columns in backtest.py
|
||||
columns = ["pair", "profit", "opents", "closets", "index", "duration",
|
||||
"open_rate", "close_rate", "open_at_end", "sell_reason"]
|
||||
if os.path.exists(file):
|
||||
if file.exists():
|
||||
with file.open() as f:
|
||||
data = json.load(f)
|
||||
trades = pd.DataFrame(data, columns=columns)
|
||||
@ -113,11 +113,7 @@ def generate_plot_file(fig, pair, tick_interval, is_last) -> None:
|
||||
pair_name = pair.replace("/", "_")
|
||||
file_name = 'freqtrade-plot-' + pair_name + '-' + tick_interval + '.html'
|
||||
|
||||
if not os.path.exists('user_data/plots'):
|
||||
try:
|
||||
os.makedirs('user_data/plots')
|
||||
except OSError as e:
|
||||
raise
|
||||
Path("user_data/plots").mkdir(parents=True, exist_ok=True)
|
||||
|
||||
plot(fig, filename=str(Path('user_data/plots').joinpath(file_name)), auto_open=False)
|
||||
if is_last:
|
||||
@ -215,13 +211,20 @@ def extract_trades_of_period(dataframe, trades) -> pd.DataFrame:
|
||||
return trades
|
||||
|
||||
|
||||
def generate_graph(pair, trades: pd.DataFrame, data: pd.DataFrame, args) -> tools.make_subplots:
|
||||
def generate_graph(
|
||||
pair: str,
|
||||
trades: pd.DataFrame,
|
||||
data: pd.DataFrame,
|
||||
indicators1: str,
|
||||
indicators2: str
|
||||
) -> tools.make_subplots:
|
||||
"""
|
||||
Generate the graph from the data generated by Backtesting or from DB
|
||||
:param pair: Pair to Display on the graph
|
||||
:param trades: All trades created
|
||||
:param data: Dataframe
|
||||
:param args: sys.argv that contrains the two params indicators1, and indicators2
|
||||
:indicators1: String Main plot indicators
|
||||
:indicators2: String Sub plot indicators
|
||||
:return: None
|
||||
"""
|
||||
|
||||
@ -322,7 +325,7 @@ def generate_graph(pair, trades: pd.DataFrame, data: pd.DataFrame, args) -> tool
|
||||
fig.append_trace(bb_lower, 1, 1)
|
||||
fig.append_trace(bb_upper, 1, 1)
|
||||
|
||||
fig = generate_row(fig=fig, row=1, raw_indicators=args.indicators1, data=data)
|
||||
fig = generate_row(fig=fig, row=1, raw_indicators=indicators1, data=data)
|
||||
fig.append_trace(buys, 1, 1)
|
||||
fig.append_trace(sells, 1, 1)
|
||||
fig.append_trace(trade_buys, 1, 1)
|
||||
@ -337,7 +340,7 @@ def generate_graph(pair, trades: pd.DataFrame, data: pd.DataFrame, args) -> tool
|
||||
fig.append_trace(volume, 2, 1)
|
||||
|
||||
# Row 3
|
||||
fig = generate_row(fig=fig, row=3, raw_indicators=args.indicators2, data=data)
|
||||
fig = generate_row(fig=fig, row=3, raw_indicators=indicators2, data=data)
|
||||
|
||||
return fig
|
||||
|
||||
@ -435,7 +438,8 @@ def analyse_and_plot_pairs(args: Namespace):
|
||||
pair=pair,
|
||||
trades=trades,
|
||||
data=dataframe,
|
||||
args=args
|
||||
indicators1=args.indicators1,
|
||||
indicators2=args.indicators2
|
||||
)
|
||||
|
||||
is_last = (False, True)[pair_counter == len(tickers)]
|
||||
|
Loading…
Reference in New Issue
Block a user