Fill up missing as part of loading data

This commit is contained in:
Matthias 2018-12-31 19:13:34 +01:00
parent 8b9cc45f41
commit ef4555735a
2 changed files with 15 additions and 5 deletions

View File

@ -10,10 +10,13 @@ from freqtrade.constants import TICKER_INTERVAL_MINUTES
logger = logging.getLogger(__name__) 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 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: 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 :return: DataFrame
""" """
logger.debug("Parsing tickerlist to dataframe") logger.debug("Parsing tickerlist to dataframe")
@ -35,6 +38,10 @@ def parse_ticker_dataframe(ticker: list) -> DataFrame:
}) })
frame.drop(frame.tail(1).index, inplace=True) # eliminate partial candle frame.drop(frame.tail(1).index, inplace=True) # eliminate partial candle
logger.debug('Dropping last candle') logger.debug('Dropping last candle')
if fill_missing:
return ohlcv_fill_up_missing_data(frame, ticker_interval)
else:
return frame return frame

View File

@ -82,6 +82,7 @@ def load_pair_history(pair: str,
timerange: TimeRange = TimeRange(None, None, 0, 0), timerange: TimeRange = TimeRange(None, None, 0, 0),
refresh_pairs: bool = False, refresh_pairs: bool = False,
exchange: Optional[Exchange] = None, exchange: Optional[Exchange] = None,
fill_up_missing: bool = True
) -> DataFrame: ) -> DataFrame:
""" """
Loads cached ticker history for the given pair. 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', logger.warning('Missing data at end for pair %s, data ends at %s',
pair, pair,
arrow.get(pairdata[-1][0] // 1000).strftime('%Y-%m-%d %H:%M:%S')) 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: else:
logger.warning('No data for pair: "%s", Interval: %s. ' logger.warning('No data for pair: "%s", Interval: %s. '
'Use --refresh-pairs-cached to download the data', 'Use --refresh-pairs-cached to download the data',
@ -123,7 +124,8 @@ def load_data(datadir: Optional[Path],
pairs: List[str], pairs: List[str],
refresh_pairs: bool = False, refresh_pairs: bool = False,
exchange: Optional[Exchange] = None, 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 Loads ticker history data for a list of pairs the given parameters
:return: dict(<pair>:<tickerlist>) :return: dict(<pair>:<tickerlist>)
@ -134,7 +136,8 @@ def load_data(datadir: Optional[Path],
hist = load_pair_history(pair=pair, ticker_interval=ticker_interval, hist = load_pair_history(pair=pair, ticker_interval=ticker_interval,
datadir=datadir, timerange=timerange, datadir=datadir, timerange=timerange,
refresh_pairs=refresh_pairs, refresh_pairs=refresh_pairs,
exchange=exchange) exchange=exchange,
fill_up_missing=fill_up_missing)
if hist is not None: if hist is not None:
result[pair] = hist result[pair] = hist
return result return result