fix: Support non-utf8 characters in pair filenames

This commit is contained in:
Matthias
2026-02-26 20:28:21 +01:00
parent 31bec6b65e
commit b8220a0a46
@@ -31,8 +31,8 @@ logger = logging.getLogger(__name__)
class IDataHandler(ABC): class IDataHandler(ABC):
_OHLCV_REGEX = r"^([a-zA-Z_\d-]+)\-(\d+[a-zA-Z]{1,2})\-?([a-zA-Z_]*)?(?=\.)" _OHLCV_REGEX = r"^([\w-]+)\-(\d+[a-zA-Z]{1,2})\-?([a-zA-Z_]*)?(?=\.)"
_TRADES_REGEX = r"^([a-zA-Z_\d-]+)\-(trades)?(?=\.)" _TRADES_REGEX = r"^([\w-]+)\-(trades)?(?=\.)"
def __init__(self, datadir: Path) -> None: def __init__(self, datadir: Path) -> None:
self._datadir = datadir self._datadir = datadir
@@ -336,11 +336,10 @@ class IDataHandler(ABC):
def rebuild_pair_from_filename(pair: str) -> str: def rebuild_pair_from_filename(pair: str) -> str:
""" """
Rebuild pair name from filename Rebuild pair name from filename
Assumes a asset name of max. 7 length to also support BTC-PERP and BTC-PERP:USD names. Replaces the first '_' with '/' and the second '_' (if present) with ':'.
e.g. BTC_USDT -> BTC/USDT, BTC_USDT_USDT -> BTC/USDT:USDT
""" """
res = re.sub(r"^(([A-Za-z\d]{1,10})|^([A-Za-z\-]{1,6}))(_)", r"\g<1>/", pair, count=1) return pair.replace("_", "/", 1).replace("_", ":", 1)
res = re.sub("_", ":", res, count=1)
return res
def ohlcv_load( def ohlcv_load(
self, self,