Move dataframe trim to within jsondatahandler
This commit is contained in:
parent
552c93abf0
commit
e861f05b75
@ -56,10 +56,6 @@ class IDataHandler(ABC):
|
|||||||
'Use `freqtrade download-data` to download the data'
|
'Use `freqtrade download-data` to download the data'
|
||||||
)
|
)
|
||||||
return pairdf
|
return pairdf
|
||||||
else:
|
|
||||||
if timerange_startup:
|
|
||||||
self._validate_pairdata(pair, pairdf, timerange_startup)
|
|
||||||
return pairdf
|
|
||||||
|
|
||||||
def _validate_pairdata(self, pair, pairdata: DataFrame, timerange: TimeRange):
|
def _validate_pairdata(self, pair, pairdata: DataFrame, timerange: TimeRange):
|
||||||
"""
|
"""
|
||||||
|
@ -78,13 +78,18 @@ class JsonDataHandler(IDataHandler):
|
|||||||
utc=True,
|
utc=True,
|
||||||
infer_datetime_format=True)
|
infer_datetime_format=True)
|
||||||
|
|
||||||
|
enddate = pairdata.iloc[-1]['date']
|
||||||
|
|
||||||
if timerange:
|
if timerange:
|
||||||
|
self._validate_pairdata(pair, pairdata, timerange)
|
||||||
pairdata = trim_dataframe(pairdata, timerange)
|
pairdata = trim_dataframe(pairdata, timerange)
|
||||||
|
|
||||||
|
# incomplete candles should only be dropped if we didn't trim the end beforehand.
|
||||||
return clean_ohlcv_dataframe(pairdata, timeframe,
|
return clean_ohlcv_dataframe(pairdata, timeframe,
|
||||||
pair=pair,
|
pair=pair,
|
||||||
fill_missing=fill_missing,
|
fill_missing=fill_missing,
|
||||||
drop_incomplete=drop_incomplete)
|
drop_incomplete=(drop_incomplete and
|
||||||
|
enddate == pairdata.iloc[-1]['date']))
|
||||||
|
|
||||||
def ohlcv_append(self, pair: str, timeframe: str, data: DataFrame) -> None:
|
def ohlcv_append(self, pair: str, timeframe: str, data: DataFrame) -> None:
|
||||||
"""
|
"""
|
||||||
@ -140,6 +145,18 @@ class JsonDataHandler(IDataHandler):
|
|||||||
|
|
||||||
return tradesdata
|
return tradesdata
|
||||||
|
|
||||||
|
def trades_purge(self, pair: str) -> bool:
|
||||||
|
"""
|
||||||
|
Remove data for this pair
|
||||||
|
:param pair: Delete data for this pair.
|
||||||
|
:return: True when deleted, false if file did not exist.
|
||||||
|
"""
|
||||||
|
filename = self._pair_trades_filename(self._datadir, pair)
|
||||||
|
if filename.is_file():
|
||||||
|
filename.unlink()
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _pair_data_filename(cls, datadir: Path, pair: str, timeframe: str) -> Path:
|
def _pair_data_filename(cls, datadir: Path, pair: str, timeframe: str) -> Path:
|
||||||
pair_s = pair.replace("/", "_")
|
pair_s = pair.replace("/", "_")
|
||||||
|
@ -369,11 +369,9 @@ def refresh_backtest_trades_data(exchange: Exchange, pairs: List[str], datadir:
|
|||||||
logger.info(f"Skipping pair {pair}...")
|
logger.info(f"Skipping pair {pair}...")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
dl_file = pair_trades_filename(datadir, pair)
|
if erase:
|
||||||
if erase and dl_file.exists():
|
if data_handler.trades_purge(pair):
|
||||||
logger.info(
|
logger.info(f'Deleting existing data for pair {pair}.')
|
||||||
f'Deleting existing data for pair {pair}.')
|
|
||||||
dl_file.unlink()
|
|
||||||
|
|
||||||
logger.info(f'Downloading trades for pair {pair}.')
|
logger.info(f'Downloading trades for pair {pair}.')
|
||||||
_download_trades_history(datadir=datadir, exchange=exchange,
|
_download_trades_history(datadir=datadir, exchange=exchange,
|
||||||
|
@ -369,8 +369,9 @@ def test_load_partial_missing(testdatadir, caplog) -> None:
|
|||||||
# timedifference in 5 minutes
|
# timedifference in 5 minutes
|
||||||
td = ((end - start).total_seconds() // 60 // 5) + 1
|
td = ((end - start).total_seconds() // 60 // 5) + 1
|
||||||
assert td != len(tickerdata['UNITTEST/BTC'])
|
assert td != len(tickerdata['UNITTEST/BTC'])
|
||||||
# This validation happens now after parsing to pandas.
|
|
||||||
end_real = arrow.get(tickerdata['UNITTEST/BTC'].iloc[-1, 0])
|
# Shift endtime with +5 - as last candle is dropped (partial candle)
|
||||||
|
end_real = arrow.get(tickerdata['UNITTEST/BTC'].iloc[-1, 0]).shift(minutes=5)
|
||||||
assert log_has(f'Missing data at end for pair '
|
assert log_has(f'Missing data at end for pair '
|
||||||
f'UNITTEST/BTC, data ends at {end_real.strftime("%Y-%m-%d %H:%M:%S")}',
|
f'UNITTEST/BTC, data ends at {end_real.strftime("%Y-%m-%d %H:%M:%S")}',
|
||||||
caplog)
|
caplog)
|
||||||
|
Loading…
Reference in New Issue
Block a user