Move plot_dataframe as freqtrade submodule

This commit is contained in:
Matthias 2019-08-22 16:02:03 +02:00
parent 60bc9f4f5e
commit 69c2b12879
4 changed files with 69 additions and 5 deletions

View File

@ -119,6 +119,7 @@ class Arguments(object):
hyperopt_cmd.set_defaults(func=start_hyperopt)
self._build_args(optionlist=ARGS_HYPEROPT, parser=hyperopt_cmd)
# Create userdir subcommand
create_userdir_cmd = subparsers.add_parser('create-userdir',
help="Create user-data directory.")
create_userdir_cmd.set_defaults(func=start_create_userdir)
@ -139,3 +140,12 @@ class Arguments(object):
)
download_data_cmd.set_defaults(func=start_download_data)
self._build_args(optionlist=ARGS_DOWNLOAD_DATA, parser=download_data_cmd)
# Add Plotting subcommand
from freqtrade.plot.plot_utils import start_plot_dataframe
plot_dataframe_cmd = subparsers.add_parser(
'plot-dataframe',
help='Plot candles with indicators.'
)
plot_dataframe_cmd.set_defaults(func=start_plot_dataframe)
self._build_args(optionlist=ARGS_PLOT_DATAFRAME, parser=plot_dataframe_cmd)

View File

@ -0,0 +1,15 @@
from argparse import Namespace
from freqtrade.state import RunMode
from freqtrade.utils import setup_utils_configuration
def start_plot_dataframe(args: Namespace) -> None:
"""
Plotting dataframe
"""
# Import here to avoid errors if plot-dependencies are not installed.
from freqtrade.plot.plotting import analyse_and_plot_pairs
config = setup_utils_configuration(args, RunMode.OTHER)
analyse_and_plot_pairs(config)

View File

@ -1,13 +1,14 @@
import logging
from pathlib import Path
from typing import Dict, List, Optional
from typing import Any, Dict, List, Optional
import pandas as pd
from freqtrade.configuration import TimeRange
from freqtrade.data import history
from freqtrade.data.btanalysis import (combine_tickers_with_mean,
create_cum_profit, load_trades)
create_cum_profit,
extract_trades_of_period, load_trades)
from freqtrade.exchange import Exchange
from freqtrade.resolvers import ExchangeResolver, StrategyResolver
@ -321,3 +322,44 @@ def store_plot_file(fig, filename: str, directory: Path, auto_open: bool = False
plot(fig, filename=str(_filename),
auto_open=auto_open)
logger.info(f"Stored plot as {_filename}")
def analyse_and_plot_pairs(config: Dict[str, Any]):
"""
From configuration provided
- Initializes plot-script
-Get tickers data
-Generate Dafaframes populated with indicators and signals
-Load trades excecuted on same periods
-Generate Plotly plot objects
-Generate plot files
:return: None
"""
plot_elements = init_plotscript(config)
trades = plot_elements['trades']
strategy = plot_elements["strategy"]
pair_counter = 0
for pair, data in plot_elements["tickers"].items():
pair_counter += 1
logger.info("analyse pair %s", pair)
tickers = {}
tickers[pair] = data
dataframe = strategy.analyze_ticker(tickers[pair], {'pair': pair})
trades_pair = trades.loc[trades['pair'] == pair]
trades_pair = extract_trades_of_period(dataframe, trades_pair)
fig = generate_candlestick_graph(
pair=pair,
data=dataframe,
trades=trades_pair,
indicators1=config["indicators1"].split(","),
indicators2=config["indicators2"].split(",")
)
store_plot_file(fig, filename=generate_plot_filename(pair, config['ticker_interval']),
directory=config['user_data_dir'] / "plot")
logger.info('End of ploting process %s plots generated', pair_counter)

View File

@ -108,6 +108,3 @@ def start_download_data(args: Namespace) -> None:
logger.info(
f"Pairs [{','.join(pairs_not_available)}] not available "
f"on exchange {config['exchange']['name']}.")
# configuration.resolve_pairs_list()
print(config)