2020-12-30 08:55:44 +00:00
|
|
|
import re
|
2022-09-18 11:31:52 +00:00
|
|
|
|
|
|
|
from freqtrade.constants import Config
|
2020-12-30 08:55:44 +00:00
|
|
|
|
|
|
|
|
2024-05-12 14:37:11 +00:00
|
|
|
def expand_pairlist(
|
2024-10-04 05:02:20 +00:00
|
|
|
wildcardpl: list[str], available_pairs: list[str], keep_invalid: bool = False
|
|
|
|
) -> list[str]:
|
2020-12-30 08:55:44 +00:00
|
|
|
"""
|
2020-12-30 09:14:22 +00:00
|
|
|
Expand pairlist potentially containing wildcards based on available markets.
|
|
|
|
This will implicitly filter all pairs in the wildcard-list which are not in available_pairs.
|
|
|
|
:param wildcardpl: List of Pairlists, which may contain regex
|
2020-12-30 09:21:05 +00:00
|
|
|
:param available_pairs: List of all available pairs (`exchange.get_markets().keys()`)
|
2021-01-14 23:13:11 +00:00
|
|
|
:param keep_invalid: If sets to True, drops invalid pairs silently while expanding regexes
|
2022-10-10 14:16:37 +00:00
|
|
|
:return: expanded pairlist, with Regexes from wildcardpl applied to match all available pairs.
|
2020-12-30 09:14:22 +00:00
|
|
|
:raises: ValueError if a wildcard is invalid (like '*/BTC' - which should be `.*/BTC`)
|
2020-12-30 08:55:44 +00:00
|
|
|
"""
|
|
|
|
result = []
|
2021-01-14 23:13:11 +00:00
|
|
|
if keep_invalid:
|
|
|
|
for pair_wc in wildcardpl:
|
|
|
|
try:
|
2021-09-05 13:41:58 +00:00
|
|
|
comp = re.compile(pair_wc, re.IGNORECASE)
|
2024-05-12 14:37:11 +00:00
|
|
|
result_partial = [pair for pair in available_pairs if re.fullmatch(comp, pair)]
|
2021-01-14 23:13:11 +00:00
|
|
|
# Add all matching pairs.
|
|
|
|
# If there are no matching pairs (Pair not on exchange) keep it.
|
|
|
|
result += result_partial or [pair_wc]
|
|
|
|
except re.error as err:
|
|
|
|
raise ValueError(f"Wildcard error in {pair_wc}, {err}")
|
|
|
|
|
2024-09-15 08:37:28 +00:00
|
|
|
# Remove wildcard pairs that didn't have a match.
|
2024-05-12 14:37:11 +00:00
|
|
|
result = [element for element in result if re.fullmatch(r"^[A-Za-z0-9:/-]+$", element)]
|
2023-08-29 15:44:39 +00:00
|
|
|
|
2021-01-14 23:13:11 +00:00
|
|
|
else:
|
|
|
|
for pair_wc in wildcardpl:
|
|
|
|
try:
|
2021-09-05 13:41:58 +00:00
|
|
|
comp = re.compile(pair_wc, re.IGNORECASE)
|
2024-05-12 14:37:11 +00:00
|
|
|
result += [pair for pair in available_pairs if re.fullmatch(comp, pair)]
|
2021-01-14 23:13:11 +00:00
|
|
|
except re.error as err:
|
|
|
|
raise ValueError(f"Wildcard error in {pair_wc}, {err}")
|
2020-12-30 08:55:44 +00:00
|
|
|
return result
|
2022-05-25 13:31:50 +00:00
|
|
|
|
|
|
|
|
2024-10-04 05:02:20 +00:00
|
|
|
def dynamic_expand_pairlist(config: Config, markets: list[str]) -> list[str]:
|
2024-05-12 14:37:11 +00:00
|
|
|
expanded_pairs = expand_pairlist(config["pairs"], markets)
|
|
|
|
if config.get("freqai", {}).get("enabled", False):
|
|
|
|
corr_pairlist = config["freqai"]["feature_parameters"]["include_corr_pairlist"]
|
|
|
|
expanded_pairs += [pair for pair in corr_pairlist if pair not in config["pairs"]]
|
2022-05-25 13:31:50 +00:00
|
|
|
|
|
|
|
return expanded_pairs
|