mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
Trim dataframe, not tickerlist
This commit is contained in:
parent
866908d2ca
commit
db520a09ee
|
@ -37,7 +37,7 @@ class IDataHandler(ABC):
|
|||
:param pair: Pair to load data for
|
||||
:param timeframe: Ticker timeframe (e.g. "5m")
|
||||
:param timerange: Limit data to be loaded to this timerange
|
||||
:param fill_up_missing: Fill missing values with "No action"-candles
|
||||
:param fill_missing: Fill missing values with "No action"-candles
|
||||
:param drop_incomplete: Drop last candle assuming it may be incomplete.
|
||||
:param startup_candles: Additional candles to load at the start of the period
|
||||
:return: DataFrame with ohlcv data, or empty DataFrame
|
||||
|
@ -75,30 +75,3 @@ class IDataHandler(ABC):
|
|||
if timerange.stoptype == 'date' and pairdata[-1][0] < timerange.stopts * 1000:
|
||||
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'))
|
||||
|
||||
@staticmethod
|
||||
def trim_tickerlist(tickerlist: List[Dict], timerange: TimeRange) -> List[Dict]:
|
||||
"""
|
||||
TODO: investigate if this is needed ... we can probably cover this in a dataframe
|
||||
Trim tickerlist based on given timerange
|
||||
"""
|
||||
if not tickerlist:
|
||||
return tickerlist
|
||||
|
||||
start_index = 0
|
||||
stop_index = len(tickerlist)
|
||||
|
||||
if timerange.starttype == 'date':
|
||||
while (start_index < len(tickerlist) and
|
||||
tickerlist[start_index][0] < timerange.startts * 1000):
|
||||
start_index += 1
|
||||
|
||||
if timerange.stoptype == 'date':
|
||||
while (stop_index > 0 and
|
||||
tickerlist[stop_index-1][0] > timerange.stopts * 1000):
|
||||
stop_index -= 1
|
||||
|
||||
if start_index > stop_index:
|
||||
raise ValueError(f'The timerange [{timerange.startts},{timerange.stopts}] is incorrect')
|
||||
|
||||
return tickerlist[start_index:stop_index]
|
||||
|
|
|
@ -8,6 +8,7 @@ from pandas import DataFrame, read_json, to_datetime
|
|||
from freqtrade import misc
|
||||
from freqtrade.configuration import TimeRange
|
||||
from freqtrade.data.converter import clean_ohlcv_dataframe
|
||||
from freqtrade.data.history import trim_dataframe
|
||||
|
||||
from .idatahandler import IDataHandler
|
||||
|
||||
|
@ -54,9 +55,15 @@ class JsonDataHandler(IDataHandler):
|
|||
drop_incomplete: bool = True,
|
||||
) -> DataFrame:
|
||||
"""
|
||||
Load data for one pair from disk.
|
||||
Internal method used to load data for one pair from disk.
|
||||
Implements the loading and conversation to a Pandas dataframe.
|
||||
:return: Dataframe
|
||||
:param pair: Pair to load data for
|
||||
:param timeframe: Ticker timeframe (e.g. "5m")
|
||||
:param timerange: Limit data to be loaded to this timerange
|
||||
:param fill_missing: Fill missing values with "No action"-candles
|
||||
:param drop_incomplete: Drop last candle assuming it may be incomplete.
|
||||
:param startup_candles: Additional candles to load at the start of the period
|
||||
:return: DataFrame with ohlcv data, or empty DataFrame
|
||||
"""
|
||||
filename = self._pair_data_filename(self._datadir, pair, timeframe)
|
||||
pairdata = read_json(filename, orient='values')
|
||||
|
@ -67,7 +74,7 @@ class JsonDataHandler(IDataHandler):
|
|||
infer_datetime_format=True)
|
||||
|
||||
if timerange:
|
||||
pairdata = IDataHandler.trim_tickerlist(pairdata, timerange)
|
||||
pairdata = trim_dataframe(pairdata, timerange)
|
||||
|
||||
return clean_ohlcv_dataframe(pairdata, timeframe,
|
||||
pair=pair,
|
||||
|
|
|
@ -285,6 +285,7 @@ def convert_ohlcv_format(config: Dict[str, Any], convert_from: str, convert_to:
|
|||
for timeframe in timeframes:
|
||||
for pair in config['pairs']:
|
||||
data = src.ohlcv_load(pair=pair, timeframe=timeframe,
|
||||
timerange=None,
|
||||
fill_missing=False,
|
||||
drop_incomplete=False,
|
||||
startup_candles=0)
|
||||
|
|
Loading…
Reference in New Issue
Block a user