From ef4555735a533f753bdf2b7feb813fa178024390 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 31 Dec 2018 19:13:34 +0100 Subject: [PATCH] Fill up missing as part of loading data --- freqtrade/data/converter.py | 11 +++++++++-- freqtrade/data/history.py | 9 ++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/freqtrade/data/converter.py b/freqtrade/data/converter.py index c1462e351..a75b1e997 100644 --- a/freqtrade/data/converter.py +++ b/freqtrade/data/converter.py @@ -10,10 +10,13 @@ from freqtrade.constants import TICKER_INTERVAL_MINUTES logger = logging.getLogger(__name__) -def parse_ticker_dataframe(ticker: list) -> DataFrame: +def parse_ticker_dataframe(ticker: list, ticker_interval: str, + fill_missing: bool = False) -> DataFrame: """ Converts a ticker-list (format ccxt.fetch_ohlcv) to a Dataframe :param ticker: ticker list, as returned by exchange.async_get_candle_history + :param ticker_interval: ticker_interval (e.g. 5m). Used to fill up eventual missing data + :param fill_missing: boolean :return: DataFrame """ logger.debug("Parsing tickerlist to dataframe") @@ -35,7 +38,11 @@ def parse_ticker_dataframe(ticker: list) -> DataFrame: }) frame.drop(frame.tail(1).index, inplace=True) # eliminate partial candle logger.debug('Dropping last candle') - return frame + + if fill_missing: + return ohlcv_fill_up_missing_data(frame, ticker_interval) + else: + return frame def ohlcv_fill_up_missing_data(dataframe: DataFrame, ticker_interval: str) -> DataFrame: diff --git a/freqtrade/data/history.py b/freqtrade/data/history.py index ae56aa6c7..475ce581d 100644 --- a/freqtrade/data/history.py +++ b/freqtrade/data/history.py @@ -82,6 +82,7 @@ def load_pair_history(pair: str, timerange: TimeRange = TimeRange(None, None, 0, 0), refresh_pairs: bool = False, exchange: Optional[Exchange] = None, + fill_up_missing: bool = True ) -> DataFrame: """ Loads cached ticker history for the given pair. @@ -110,7 +111,7 @@ def load_pair_history(pair: str, logger.warning('Missing data at end for pair %s, data ends at %s', pair, arrow.get(pairdata[-1][0] // 1000).strftime('%Y-%m-%d %H:%M:%S')) - return parse_ticker_dataframe(pairdata) + return parse_ticker_dataframe(pairdata, ticker_interval, fill_up_missing) else: logger.warning('No data for pair: "%s", Interval: %s. ' 'Use --refresh-pairs-cached to download the data', @@ -123,7 +124,8 @@ def load_data(datadir: Optional[Path], pairs: List[str], refresh_pairs: bool = False, exchange: Optional[Exchange] = None, - timerange: TimeRange = TimeRange(None, None, 0, 0)) -> Dict[str, DataFrame]: + timerange: TimeRange = TimeRange(None, None, 0, 0), + fill_up_missing: bool = True) -> Dict[str, DataFrame]: """ Loads ticker history data for a list of pairs the given parameters :return: dict(:) @@ -134,7 +136,8 @@ def load_data(datadir: Optional[Path], hist = load_pair_history(pair=pair, ticker_interval=ticker_interval, datadir=datadir, timerange=timerange, refresh_pairs=refresh_pairs, - exchange=exchange) + exchange=exchange, + fill_up_missing=fill_up_missing) if hist is not None: result[pair] = hist return result