From 021791e2c805a4ba66f9988a1c66d177dfa18a99 Mon Sep 17 00:00:00 2001 From: Jonathan Raviotta Date: Wed, 4 Sep 2019 20:56:25 -0400 Subject: [PATCH] fixed error checking --- freqtrade/data/history.py | 6 ++-- freqtrade/misc.py | 21 ------------- freqtrade/plot/plotting.py | 61 +++++++++++++++++++++----------------- 3 files changed, 36 insertions(+), 52 deletions(-) diff --git a/freqtrade/data/history.py b/freqtrade/data/history.py index ec7e769ac..e6863c9bd 100644 --- a/freqtrade/data/history.py +++ b/freqtrade/data/history.py @@ -128,9 +128,9 @@ def load_pair_history(pair: str, drop_incomplete=drop_incomplete) else: logger.warning( - f'No history data for pair: "{pair}", interval: {ticker_interval}. ' - 'Use --refresh-pairs-cached option or `freqtrade download-data` ' - 'script to download the data' + f'No history data for pair: "{pair}", interval: {ticker_interval}, in {datadir}. ' + 'Provide the correct path to datadir in config.json, or download data with ' + '--refresh-pairs-cached option or `freqtrade download-data`. ' ) return None diff --git a/freqtrade/misc.py b/freqtrade/misc.py index 7eef795e9..12a90a14d 100644 --- a/freqtrade/misc.py +++ b/freqtrade/misc.py @@ -3,7 +3,6 @@ Various tool function for Freqtrade and scripts """ import gzip import logging -from os import chdir import re from datetime import datetime from pathlib import Path @@ -115,23 +114,3 @@ def deep_merge_dicts(source, destination): destination[key] = value return destination - - -def find_project_root(path=None): - """Locates root directory of the project. - Root is defined by existence of "LICENSE" and the dir 'freqtrade'. - :param path: pathlib.Path object, or string pointing to project root directory. - :return: path to project root directory - """ - if path is None: - path = Path(__file__).parent - i = 0 - try: - chdir(path) - assert Path('LICENSE').is_file() and Path('freqtrade').exists() - except AssertionError: - while i < 5 and not (Path(path, 'LICENSE').is_file() and Path(path, 'freqtrade').exists()): - path = Path(path).parent - i += 1 - logger.info(f'project_root is {path}') - return path diff --git a/freqtrade/plot/plotting.py b/freqtrade/plot/plotting.py index 309f4bfa3..df0dab889 100644 --- a/freqtrade/plot/plotting.py +++ b/freqtrade/plot/plotting.py @@ -3,7 +3,7 @@ from pathlib import Path from typing import Any, Dict, List import pandas as pd - +from freqtrade import OperationalException from freqtrade.configuration import TimeRange from freqtrade.data import history from freqtrade.data.btanalysis import (combine_tickers_with_mean, @@ -33,24 +33,29 @@ def init_plotscript(config): pairs = config["pairs"] else: pairs = config["exchange"]["pair_whitelist"] - assert pairs is not None, ('No pairs available in config.') + if pairs is None: + raise OperationalException('No pairs available in config.') # Set timerange to use timerange = TimeRange.parse_timerange(config.get("timerange")) + if timerange is None: + raise OperationalException('Could not parse timerange in config.') tickers = history.load_data( - datadir=Path(config.get("datadir"), config.get("exchange").get("name")), + datadir=Path(str(config.get("datadir"))), pairs=pairs, ticker_interval=config.get('ticker_interval', '5m'), timerange=timerange, ) - assert tickers is not None, ('No ticker data available as specified in config.') + if tickers is None: + raise OperationalException('No ticker data available as specified in config.') trades = load_trades(config['trade_source'], db_url=config.get('db_url'), exportfilename=config.get('exportfilename'), ) - assert trades is not None, ('No trades available as specified in config.') + if trades is None: + raise OperationalException('No trades available as specified in config.') return {"tickers": tickers, "trades": trades, @@ -342,34 +347,34 @@ def load_and_plot_trades(config: Dict[str, Any]): plot_elements = init_plotscript(config) trades = plot_elements['trades'] - if trades is None: - raise ValueError('No trades to analyze') - else: - pair_counter = 0 - for pair, data in plot_elements["tickers"].items(): - pair_counter += 1 - logger.info("analyse pair %s", pair) - tickers = {} - tickers[pair] = data + # if trades is None: + # # raise ValueError('No trades to analyze') + # else: + 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}) - logger.debug(f'pair: {pair}') + dataframe = strategy.analyze_ticker(tickers[pair], {'pair': pair}) + logger.debug(f'pair: {pair}') - trades_pair = trades.loc[trades['pair'] == pair] - trades_pair = extract_trades_of_period(dataframe, trades_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"], - indicators2=config["indicators2"], - ) + fig = generate_candlestick_graph( + pair=pair, + data=dataframe, + trades=trades_pair, + indicators1=config["indicators1"], + indicators2=config["indicators2"], + ) - store_plot_file(fig, filename=generate_plot_filename(pair, config['ticker_interval']), - directory=config['user_data_dir'] / "plot") + store_plot_file(fig, filename=generate_plot_filename(pair, config['ticker_interval']), + directory=config['user_data_dir'] / "plot") - logger.info('End of plotting process. %s plots generated', pair_counter) + logger.info('End of plotting process. %s plots generated', pair_counter) def plot_profit(config: Dict[str, Any]) -> None: