Skip to content

Commit bc0aeb3

Browse files
authored
Merge pull request freqtrade#12876 from freqtrade/fix/chinese_char_pairs
Allow non-ascii characters in pair names
2 parents 1e33ea0 + 84a680d commit bc0aeb3

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

freqtrade/data/history/datahandlers/idatahandler.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131

3232

3333
class IDataHandler(ABC):
34-
_OHLCV_REGEX = r"^([a-zA-Z_\d-]+)\-(\d+[a-zA-Z]{1,2})\-?([a-zA-Z_]*)?(?=\.)"
35-
_TRADES_REGEX = r"^([a-zA-Z_\d-]+)\-(trades)?(?=\.)"
34+
_OHLCV_REGEX = r"^([\w-]+)\-(\d+[a-zA-Z]{1,2})\-?([a-zA-Z_]*)?(?=\.)"
35+
_TRADES_REGEX = r"^([\w-]+)\-(trades)?(?=\.)"
3636

3737
def __init__(self, datadir: Path) -> None:
3838
self._datadir = datadir
@@ -336,11 +336,10 @@ def rebuild_timeframe_from_filename(timeframe: str) -> str:
336336
def rebuild_pair_from_filename(pair: str) -> str:
337337
"""
338338
Rebuild pair name from filename
339-
Assumes a asset name of max. 7 length to also support BTC-PERP and BTC-PERP:USD names.
339+
Replaces the first '_' with '/' and the second '_' (if present) with ':'.
340+
e.g. BTC_USDT -> BTC/USDT, BTC_USDT_USDT -> BTC/USDT:USDT
340341
"""
341-
res = re.sub(r"^(([A-Za-z\d]{1,10})|^([A-Za-z\-]{1,6}))(_)", r"\g<1>/", pair, count=1)
342-
res = re.sub("_", ":", res, count=1)
343-
return res
342+
return pair.replace("_", "/", 1).replace("_", ":", 1)
344343

345344
def ohlcv_load(
346345
self,

freqtrade/plugins/pairlist/pairlist_helpers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ def expand_pairlist(
2828
raise ValueError(f"Wildcard error in {pair_wc}, {err}")
2929

3030
# Remove wildcard pairs that didn't have a match.
31-
result = [element for element in result if re.fullmatch(r"^[A-Za-z0-9:/-]+$", element)]
31+
result = [
32+
element
33+
for element in result
34+
if re.fullmatch(r"^[\w:/-]+$", element) and "_" not in element
35+
]
3236

3337
else:
3438
for pair_wc in wildcardpl:

tests/data/test_datahandler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ def test_datahandler_ohlcv_regex(filename, pair, timeframe, candletype):
5656
("USDT_BUSD", "USDT/BUSD"),
5757
("BTC_USDT_USDT", "BTC/USDT:USDT"), # Futures
5858
("XRP_USDT_USDT", "XRP/USDT:USDT"), # futures
59-
("BTC-PERP", "BTC-PERP"),
60-
("BTC-PERP_USDT", "BTC-PERP:USDT"),
59+
("XYZ-XRP_USDT_USDT", "XYZ-XRP/USDT:USDT"), # hip3 futures
6160
("UNITTEST_USDT", "UNITTEST/USDT"),
61+
("币安人生_USDT_USDT", "币安人生/USDT:USDT"), # futures
6262
],
6363
)
6464
def test_rebuild_pair_from_filename(pair, expected):

0 commit comments

Comments
 (0)