Add fallback to load 1M files as well as 1Mo files
This commit is contained in:
parent
a1048fb619
commit
2e65a1793d
@ -77,7 +77,8 @@ class HDF5DataHandler(IDataHandler):
|
|||||||
key = self._pair_ohlcv_key(pair, timeframe)
|
key = self._pair_ohlcv_key(pair, timeframe)
|
||||||
_data = data.copy()
|
_data = data.copy()
|
||||||
|
|
||||||
filename = self._pair_data_filename(self._datadir, pair, timeframe, candle_type)
|
filename = self._pair_data_filename(
|
||||||
|
self._datadir, pair, self.timeframe_to_file(timeframe), candle_type)
|
||||||
self.create_dir_if_needed(filename)
|
self.create_dir_if_needed(filename)
|
||||||
|
|
||||||
_data.loc[:, self._columns].to_hdf(
|
_data.loc[:, self._columns].to_hdf(
|
||||||
@ -104,12 +105,16 @@ class HDF5DataHandler(IDataHandler):
|
|||||||
filename = self._pair_data_filename(
|
filename = self._pair_data_filename(
|
||||||
self._datadir,
|
self._datadir,
|
||||||
pair,
|
pair,
|
||||||
timeframe,
|
self.timeframe_to_file(timeframe),
|
||||||
candle_type=candle_type
|
candle_type=candle_type
|
||||||
)
|
)
|
||||||
|
|
||||||
if not filename.exists():
|
if not filename.exists():
|
||||||
return pd.DataFrame(columns=self._columns)
|
# Fallback mode for 1M files
|
||||||
|
filename = self._pair_data_filename(
|
||||||
|
self._datadir, pair, timeframe, candle_type=candle_type)
|
||||||
|
if not filename.exists():
|
||||||
|
return pd.DataFrame(columns=self._columns)
|
||||||
where = []
|
where = []
|
||||||
if timerange:
|
if timerange:
|
||||||
if timerange.starttype == 'date':
|
if timerange.starttype == 'date':
|
||||||
|
@ -98,7 +98,8 @@ class IDataHandler(ABC):
|
|||||||
:param candle_type: Any of the enum CandleType (must match trading mode!)
|
:param candle_type: Any of the enum CandleType (must match trading mode!)
|
||||||
:return: True when deleted, false if file did not exist.
|
:return: True when deleted, false if file did not exist.
|
||||||
"""
|
"""
|
||||||
filename = self._pair_data_filename(self._datadir, pair, timeframe, candle_type)
|
filename = self._pair_data_filename(
|
||||||
|
self._datadir, pair, self.timeframe_to_file(timeframe), candle_type)
|
||||||
if filename.exists():
|
if filename.exists():
|
||||||
filename.unlink()
|
filename.unlink()
|
||||||
return True
|
return True
|
||||||
@ -201,7 +202,7 @@ class IDataHandler(ABC):
|
|||||||
datadir = datadir.joinpath('futures')
|
datadir = datadir.joinpath('futures')
|
||||||
candle = f"-{candle_type}"
|
candle = f"-{candle_type}"
|
||||||
filename = datadir.joinpath(
|
filename = datadir.joinpath(
|
||||||
f'{pair_s}-{cls.timeframe_to_file(timeframe)}{candle}.{cls._get_file_extension()}')
|
f'{pair_s}-{timeframe}{candle}.{cls._get_file_extension()}')
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -220,7 +221,7 @@ class IDataHandler(ABC):
|
|||||||
converts timeframe from disk to file
|
converts timeframe from disk to file
|
||||||
Replaces mo with M (to avoid problems on case-insensitive filesystems)
|
Replaces mo with M (to avoid problems on case-insensitive filesystems)
|
||||||
"""
|
"""
|
||||||
return re.sub('mo', 'M', timeframe, flags=re.IGNORECASE)
|
return re.sub('1mo', '1M', timeframe, flags=re.IGNORECASE)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def rebuild_pair_from_filename(pair: str) -> str:
|
def rebuild_pair_from_filename(pair: str) -> str:
|
||||||
|
@ -77,7 +77,8 @@ class JsonDataHandler(IDataHandler):
|
|||||||
:param candle_type: Any of the enum CandleType (must match trading mode!)
|
:param candle_type: Any of the enum CandleType (must match trading mode!)
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
filename = self._pair_data_filename(self._datadir, pair, timeframe, candle_type)
|
filename = self._pair_data_filename(
|
||||||
|
self._datadir, pair, self.timeframe_to_file(timeframe), candle_type)
|
||||||
self.create_dir_if_needed(filename)
|
self.create_dir_if_needed(filename)
|
||||||
_data = data.copy()
|
_data = data.copy()
|
||||||
# Convert date to int
|
# Convert date to int
|
||||||
@ -103,9 +104,14 @@ class JsonDataHandler(IDataHandler):
|
|||||||
:param candle_type: Any of the enum CandleType (must match trading mode!)
|
:param candle_type: Any of the enum CandleType (must match trading mode!)
|
||||||
:return: DataFrame with ohlcv data, or empty DataFrame
|
:return: DataFrame with ohlcv data, or empty DataFrame
|
||||||
"""
|
"""
|
||||||
filename = self._pair_data_filename(self._datadir, pair, timeframe, candle_type=candle_type)
|
filename = self._pair_data_filename(
|
||||||
|
self._datadir, pair, self.timeframe_to_file(timeframe), candle_type=candle_type)
|
||||||
if not filename.exists():
|
if not filename.exists():
|
||||||
return DataFrame(columns=self._columns)
|
# Fallback mode for 1M files
|
||||||
|
filename = self._pair_data_filename(
|
||||||
|
self._datadir, pair, timeframe, candle_type=candle_type)
|
||||||
|
if not filename.exists():
|
||||||
|
return DataFrame(columns=self._columns)
|
||||||
try:
|
try:
|
||||||
pairdata = read_json(filename, orient='values')
|
pairdata = read_json(filename, orient='values')
|
||||||
pairdata.columns = self._columns
|
pairdata.columns = self._columns
|
||||||
|
@ -158,21 +158,22 @@ def test_testdata_path(testdatadir) -> None:
|
|||||||
assert str(Path('tests') / 'testdata') in str(testdatadir)
|
assert str(Path('tests') / 'testdata') in str(testdatadir)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("pair,expected_result,candle_type", [
|
@pytest.mark.parametrize("pair,timeframe,expected_result,candle_type", [
|
||||||
("ETH/BTC", 'freqtrade/hello/world/ETH_BTC-5m.json', ""),
|
("ETH/BTC", "5m", "freqtrade/hello/world/ETH_BTC-5m.json", ""),
|
||||||
("Fabric Token/ETH", 'freqtrade/hello/world/Fabric_Token_ETH-5m.json', ""),
|
("ETH/USDT", "1M", "freqtrade/hello/world/ETH_USDT-1Mo.json", ""),
|
||||||
("ETHH20", 'freqtrade/hello/world/ETHH20-5m.json', ""),
|
("Fabric Token/ETH", "5m", "freqtrade/hello/world/Fabric_Token_ETH-5m.json", ""),
|
||||||
(".XBTBON2H", 'freqtrade/hello/world/_XBTBON2H-5m.json', ""),
|
("ETHH20", "5m", "freqtrade/hello/world/ETHH20-5m.json", ""),
|
||||||
("ETHUSD.d", 'freqtrade/hello/world/ETHUSD_d-5m.json', ""),
|
(".XBTBON2H", "5m", "freqtrade/hello/world/_XBTBON2H-5m.json", ""),
|
||||||
("ACC_OLD/BTC", 'freqtrade/hello/world/ACC_OLD_BTC-5m.json', ""),
|
("ETHUSD.d", "5m", "freqtrade/hello/world/ETHUSD_d-5m.json", ""),
|
||||||
("ETH/BTC", 'freqtrade/hello/world/futures/ETH_BTC-5m-mark.json', "mark"),
|
("ACC_OLD/BTC", "5m", "freqtrade/hello/world/ACC_OLD_BTC-5m.json", ""),
|
||||||
("ACC_OLD/BTC", 'freqtrade/hello/world/futures/ACC_OLD_BTC-5m-index.json', "index"),
|
("ETH/BTC", "5m", "freqtrade/hello/world/futures/ETH_BTC-5m-mark.json", "mark"),
|
||||||
|
("ACC_OLD/BTC", "5m", "freqtrade/hello/world/futures/ACC_OLD_BTC-5m-index.json", "index"),
|
||||||
])
|
])
|
||||||
def test_json_pair_data_filename(pair, expected_result, candle_type):
|
def test_json_pair_data_filename(pair, timeframe, expected_result, candle_type):
|
||||||
fn = JsonDataHandler._pair_data_filename(
|
fn = JsonDataHandler._pair_data_filename(
|
||||||
Path('freqtrade/hello/world'),
|
Path('freqtrade/hello/world'),
|
||||||
pair,
|
pair,
|
||||||
'5m',
|
JsonDataHandler.timeframe_to_file(timeframe),
|
||||||
CandleType.from_string(candle_type)
|
CandleType.from_string(candle_type)
|
||||||
)
|
)
|
||||||
assert isinstance(fn, Path)
|
assert isinstance(fn, Path)
|
||||||
@ -180,7 +181,7 @@ def test_json_pair_data_filename(pair, expected_result, candle_type):
|
|||||||
fn = JsonGzDataHandler._pair_data_filename(
|
fn = JsonGzDataHandler._pair_data_filename(
|
||||||
Path('freqtrade/hello/world'),
|
Path('freqtrade/hello/world'),
|
||||||
pair,
|
pair,
|
||||||
'5m',
|
JsonGzDataHandler.timeframe_to_file(timeframe),
|
||||||
candle_type=CandleType.from_string(candle_type)
|
candle_type=CandleType.from_string(candle_type)
|
||||||
)
|
)
|
||||||
assert isinstance(fn, Path)
|
assert isinstance(fn, Path)
|
||||||
|
Loading…
Reference in New Issue
Block a user