Further enhance pair retrieval

This commit is contained in:
Matthias
2021-11-28 15:03:55 +01:00
parent 8d70672bee
commit 7faa7539b4
4 changed files with 30 additions and 3 deletions

View File

@@ -33,7 +33,7 @@ class HDF5DataHandler(IDataHandler):
cls._OHLCV_REGEX, p.name
) for p in datadir.glob("*.h5")
]
return [(match[1].replace('_', '/'), match[2], match[3]) for match in _tmp
return [(cls.rebuild_pair_from_filename(match[1]), match[2], match[3]) for match in _tmp
if match and len(match.groups()) > 1]
@classmethod

View File

@@ -4,6 +4,7 @@ It's subclasses handle and storing data from disk.
"""
import logging
import re
from abc import ABC, abstractclassmethod, abstractmethod
from copy import deepcopy
from datetime import datetime, timezone
@@ -23,7 +24,7 @@ logger = logging.getLogger(__name__)
class IDataHandler(ABC):
_OHLCV_REGEX = r'^([a-zA-Z_]+)\-(\d+\S)\-?([a-zA-Z_]*)?(?=\.)'
_OHLCV_REGEX = r'^([a-zA-Z_-]+)\-(\d+\S)\-?([a-zA-Z_]*)?(?=\.)'
def __init__(self, datadir: Path) -> None:
self._datadir = datadir
@@ -166,6 +167,16 @@ class IDataHandler(ABC):
"""
return trades_remove_duplicates(self._trades_load(pair, timerange=timerange))
@staticmethod
def rebuild_pair_from_filename(pair: str) -> str:
"""
Rebuild pair name from filename
Assumes a asset name of max. 7 length to also support BTC-PERP and BTC-PERP:USD names.
"""
res = re.sub(r'^(.{1,7})(_)', r'\g<1>/', pair, 1)
res = re.sub('_', ':', res, 1)
return res
def ohlcv_load(self, pair, timeframe: str,
timerange: Optional[TimeRange] = None,
fill_missing: bool = True,

View File

@@ -33,7 +33,7 @@ class JsonDataHandler(IDataHandler):
re.search(
cls._OHLCV_REGEX, p.name
) for p in datadir.glob(f"*.{cls._get_file_extension()}")]
return [(match[1].replace('_', '/'), match[2], match[3]) for match in _tmp
return [(cls.rebuild_pair_from_filename(match[1]), match[2], match[3]) for match in _tmp
if match and len(match.groups()) > 1]
@classmethod