commit
b4a0591429
@ -61,7 +61,7 @@ def load_tickerdata_file(datadir: Path, pair: str, ticker_interval: str,
|
|||||||
timerange: Optional[TimeRange] = None) -> Optional[list]:
|
timerange: Optional[TimeRange] = None) -> Optional[list]:
|
||||||
"""
|
"""
|
||||||
Load a pair from file, either .json.gz or .json
|
Load a pair from file, either .json.gz or .json
|
||||||
:return: tickerlist or None if unsuccesful
|
:return: tickerlist or None if unsuccessful
|
||||||
"""
|
"""
|
||||||
filename = pair_data_filename(datadir, pair, ticker_interval)
|
filename = pair_data_filename(datadir, pair, ticker_interval)
|
||||||
pairdata = misc.file_load_json(filename)
|
pairdata = misc.file_load_json(filename)
|
||||||
|
@ -17,11 +17,11 @@ def start_plot_dataframe(args: Namespace) -> None:
|
|||||||
Entrypoint for dataframe plotting
|
Entrypoint for dataframe plotting
|
||||||
"""
|
"""
|
||||||
# Import here to avoid errors if plot-dependencies are not installed.
|
# Import here to avoid errors if plot-dependencies are not installed.
|
||||||
from freqtrade.plot.plotting import analyse_and_plot_pairs
|
from freqtrade.plot.plotting import load_and_plot_trades
|
||||||
validate_plot_args(args)
|
validate_plot_args(args)
|
||||||
config = setup_utils_configuration(args, RunMode.PLOT)
|
config = setup_utils_configuration(args, RunMode.PLOT)
|
||||||
|
|
||||||
analyse_and_plot_pairs(config)
|
load_and_plot_trades(config)
|
||||||
|
|
||||||
|
|
||||||
def start_plot_profit(args: Namespace) -> None:
|
def start_plot_profit(args: Namespace) -> None:
|
||||||
|
@ -3,7 +3,6 @@ from pathlib import Path
|
|||||||
from typing import Any, Dict, List
|
from typing import Any, Dict, List
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
from freqtrade.configuration import TimeRange
|
from freqtrade.configuration import TimeRange
|
||||||
from freqtrade.data import history
|
from freqtrade.data import history
|
||||||
from freqtrade.data.btanalysis import (combine_tickers_with_mean,
|
from freqtrade.data.btanalysis import (combine_tickers_with_mean,
|
||||||
@ -324,7 +323,7 @@ def store_plot_file(fig, filename: str, directory: Path, auto_open: bool = False
|
|||||||
logger.info(f"Stored plot as {_filename}")
|
logger.info(f"Stored plot as {_filename}")
|
||||||
|
|
||||||
|
|
||||||
def analyse_and_plot_pairs(config: Dict[str, Any]):
|
def load_and_plot_trades(config: Dict[str, Any]):
|
||||||
"""
|
"""
|
||||||
From configuration provided
|
From configuration provided
|
||||||
- Initializes plot-script
|
- Initializes plot-script
|
||||||
@ -339,7 +338,6 @@ def analyse_and_plot_pairs(config: Dict[str, Any]):
|
|||||||
|
|
||||||
plot_elements = init_plotscript(config)
|
plot_elements = init_plotscript(config)
|
||||||
trades = plot_elements['trades']
|
trades = plot_elements['trades']
|
||||||
|
|
||||||
pair_counter = 0
|
pair_counter = 0
|
||||||
for pair, data in plot_elements["tickers"].items():
|
for pair, data in plot_elements["tickers"].items():
|
||||||
pair_counter += 1
|
pair_counter += 1
|
||||||
@ -348,7 +346,6 @@ def analyse_and_plot_pairs(config: Dict[str, Any]):
|
|||||||
tickers[pair] = data
|
tickers[pair] = data
|
||||||
|
|
||||||
dataframe = strategy.analyze_ticker(tickers[pair], {'pair': pair})
|
dataframe = strategy.analyze_ticker(tickers[pair], {'pair': pair})
|
||||||
|
|
||||||
trades_pair = trades.loc[trades['pair'] == pair]
|
trades_pair = trades.loc[trades['pair'] == pair]
|
||||||
trades_pair = extract_trades_of_period(dataframe, trades_pair)
|
trades_pair = extract_trades_of_period(dataframe, trades_pair)
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ from freqtrade.data import history
|
|||||||
from freqtrade.data.btanalysis import create_cum_profit, load_backtest_data
|
from freqtrade.data.btanalysis import create_cum_profit, load_backtest_data
|
||||||
from freqtrade.plot.plot_utils import start_plot_dataframe, start_plot_profit
|
from freqtrade.plot.plot_utils import start_plot_dataframe, start_plot_profit
|
||||||
from freqtrade.plot.plotting import (add_indicators, add_profit,
|
from freqtrade.plot.plotting import (add_indicators, add_profit,
|
||||||
analyse_and_plot_pairs,
|
load_and_plot_trades,
|
||||||
generate_candlestick_graph,
|
generate_candlestick_graph,
|
||||||
generate_plot_filename,
|
generate_plot_filename,
|
||||||
generate_profit_graph, init_plotscript,
|
generate_profit_graph, init_plotscript,
|
||||||
@ -32,7 +32,7 @@ def find_trace_in_fig_data(data, search_string: str):
|
|||||||
return next(matches)
|
return next(matches)
|
||||||
|
|
||||||
|
|
||||||
def generage_empty_figure():
|
def generate_empty_figure():
|
||||||
return make_subplots(
|
return make_subplots(
|
||||||
rows=3,
|
rows=3,
|
||||||
cols=1,
|
cols=1,
|
||||||
@ -72,7 +72,7 @@ def test_add_indicators(default_conf, testdatadir, caplog):
|
|||||||
# Generate buy/sell signals and indicators
|
# Generate buy/sell signals and indicators
|
||||||
strat = DefaultStrategy(default_conf)
|
strat = DefaultStrategy(default_conf)
|
||||||
data = strat.analyze_ticker(data, {'pair': pair})
|
data = strat.analyze_ticker(data, {'pair': pair})
|
||||||
fig = generage_empty_figure()
|
fig = generate_empty_figure()
|
||||||
|
|
||||||
# Row 1
|
# Row 1
|
||||||
fig1 = add_indicators(fig=deepcopy(fig), row=1, indicators=indicators1, data=data)
|
fig1 = add_indicators(fig=deepcopy(fig), row=1, indicators=indicators1, data=data)
|
||||||
@ -94,7 +94,7 @@ def test_add_indicators(default_conf, testdatadir, caplog):
|
|||||||
|
|
||||||
|
|
||||||
def test_plot_trades(testdatadir, caplog):
|
def test_plot_trades(testdatadir, caplog):
|
||||||
fig1 = generage_empty_figure()
|
fig1 = generate_empty_figure()
|
||||||
# nothing happens when no trades are available
|
# nothing happens when no trades are available
|
||||||
fig = plot_trades(fig1, None)
|
fig = plot_trades(fig1, None)
|
||||||
assert fig == fig1
|
assert fig == fig1
|
||||||
@ -210,7 +210,7 @@ def test_generate_Plot_filename():
|
|||||||
|
|
||||||
|
|
||||||
def test_generate_plot_file(mocker, caplog):
|
def test_generate_plot_file(mocker, caplog):
|
||||||
fig = generage_empty_figure()
|
fig = generate_empty_figure()
|
||||||
plot_mock = mocker.patch("freqtrade.plot.plotting.plot", MagicMock())
|
plot_mock = mocker.patch("freqtrade.plot.plotting.plot", MagicMock())
|
||||||
store_plot_file(fig, filename="freqtrade-plot-UNITTEST_BTC-5m.html",
|
store_plot_file(fig, filename="freqtrade-plot-UNITTEST_BTC-5m.html",
|
||||||
directory=Path("user_data/plots"))
|
directory=Path("user_data/plots"))
|
||||||
@ -230,7 +230,7 @@ def test_add_profit(testdatadir):
|
|||||||
|
|
||||||
df = history.load_pair_history(pair="POWR/BTC", ticker_interval='5m',
|
df = history.load_pair_history(pair="POWR/BTC", ticker_interval='5m',
|
||||||
datadir=testdatadir, timerange=timerange)
|
datadir=testdatadir, timerange=timerange)
|
||||||
fig = generage_empty_figure()
|
fig = generate_empty_figure()
|
||||||
|
|
||||||
cum_profits = create_cum_profit(df.set_index('date'),
|
cum_profits = create_cum_profit(df.set_index('date'),
|
||||||
bt_data[bt_data["pair"] == 'POWR/BTC'],
|
bt_data[bt_data["pair"] == 'POWR/BTC'],
|
||||||
@ -279,7 +279,7 @@ def test_generate_profit_graph(testdatadir):
|
|||||||
|
|
||||||
|
|
||||||
def test_start_plot_dataframe(mocker):
|
def test_start_plot_dataframe(mocker):
|
||||||
aup = mocker.patch("freqtrade.plot.plotting.analyse_and_plot_pairs", MagicMock())
|
aup = mocker.patch("freqtrade.plot.plotting.load_and_plot_trades", MagicMock())
|
||||||
args = [
|
args = [
|
||||||
"--config", "config.json.example",
|
"--config", "config.json.example",
|
||||||
"plot-dataframe",
|
"plot-dataframe",
|
||||||
@ -293,7 +293,7 @@ def test_start_plot_dataframe(mocker):
|
|||||||
assert called_config['pairs'] == ["ETH/BTC"]
|
assert called_config['pairs'] == ["ETH/BTC"]
|
||||||
|
|
||||||
|
|
||||||
def test_analyse_and_plot_pairs(default_conf, mocker, caplog, testdatadir):
|
def test_load_and_plot_trades(default_conf, mocker, caplog, testdatadir):
|
||||||
default_conf['trade_source'] = 'file'
|
default_conf['trade_source'] = 'file'
|
||||||
default_conf["datadir"] = testdatadir
|
default_conf["datadir"] = testdatadir
|
||||||
default_conf['exportfilename'] = str(testdatadir / "backtest-result_test.json")
|
default_conf['exportfilename'] = str(testdatadir / "backtest-result_test.json")
|
||||||
@ -308,7 +308,7 @@ def test_analyse_and_plot_pairs(default_conf, mocker, caplog, testdatadir):
|
|||||||
generate_candlestick_graph=candle_mock,
|
generate_candlestick_graph=candle_mock,
|
||||||
store_plot_file=store_mock
|
store_plot_file=store_mock
|
||||||
)
|
)
|
||||||
analyse_and_plot_pairs(default_conf)
|
load_and_plot_trades(default_conf)
|
||||||
|
|
||||||
# Both mocks should be called once per pair
|
# Both mocks should be called once per pair
|
||||||
assert candle_mock.call_count == 2
|
assert candle_mock.call_count == 2
|
||||||
|
Loading…
Reference in New Issue
Block a user