Add expand_pairlist method
This commit is contained in:
parent
2fdda8e448
commit
704cf14383
@ -208,7 +208,7 @@ class Exchange:
|
||||
return self._api.precisionMode
|
||||
|
||||
def get_markets(self, base_currencies: List[str] = None, quote_currencies: List[str] = None,
|
||||
pairs_only: bool = False, active_only: bool = False) -> Dict:
|
||||
pairs_only: bool = False, active_only: bool = False) -> Dict[str, Any]:
|
||||
"""
|
||||
Return exchange ccxt markets, filtered out by base currency and quote currency
|
||||
if this was requested in parameters.
|
||||
|
18
freqtrade/plugins/pairlist/pairlist_helpers.py
Normal file
18
freqtrade/plugins/pairlist/pairlist_helpers.py
Normal file
@ -0,0 +1,18 @@
|
||||
import re
|
||||
from typing import List
|
||||
|
||||
|
||||
def expand_pairlist(wildcardpl: List[str], available_pairs: List[str]) -> List[str]:
|
||||
"""
|
||||
TODO: Add docstring here
|
||||
"""
|
||||
result = []
|
||||
for pair_wc in wildcardpl:
|
||||
try:
|
||||
comp = re.compile(pair_wc)
|
||||
result += [
|
||||
pair for pair in available_pairs if re.match(comp, pair)
|
||||
]
|
||||
except re.error as err:
|
||||
raise ValueError(f"Wildcard error in {pair_wc}, {err}")
|
||||
return result
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
PairList manager class
|
||||
"""
|
||||
from freqtrade.plugins.pairlist.pairlist_helpers import expand_pairlist
|
||||
import logging
|
||||
from copy import deepcopy
|
||||
from typing import Any, Dict, List
|
||||
@ -55,6 +56,13 @@ class PairListManager():
|
||||
"""
|
||||
return self._blacklist
|
||||
|
||||
@property
|
||||
def expanded_blacklist(self) -> List[str]:
|
||||
"""
|
||||
Has the expanded blacklist (including wildcard expansion)
|
||||
"""
|
||||
return expand_pairlist(self._blacklist, self._exchange.get_markets().keys())
|
||||
|
||||
@property
|
||||
def name_list(self) -> List[str]:
|
||||
"""
|
||||
@ -121,7 +129,7 @@ class PairListManager():
|
||||
:return: pairlist - blacklisted pairs
|
||||
"""
|
||||
for pair in deepcopy(pairlist):
|
||||
if pair in self._blacklist:
|
||||
if pair in self.expanded_blacklist:
|
||||
logmethod(f"Pair {pair} in your blacklist. Removing it from whitelist...")
|
||||
pairlist.remove(pair)
|
||||
return pairlist
|
||||
|
@ -6,6 +6,7 @@ import pytest
|
||||
|
||||
from freqtrade.constants import AVAILABLE_PAIRLISTS
|
||||
from freqtrade.exceptions import OperationalException
|
||||
from freqtrade.plugins.pairlist.pairlist_helpers import expand_pairlist
|
||||
from freqtrade.plugins.pairlistmanager import PairListManager
|
||||
from freqtrade.resolvers import PairListResolver
|
||||
from tests.conftest import get_patched_freqtradebot, log_has, log_has_re
|
||||
@ -804,3 +805,34 @@ def test_performance_filter(mocker, whitelist_conf, pairlists, pair_allowlist, o
|
||||
freqtrade.pairlists.refresh_pairlist()
|
||||
allowlist = freqtrade.pairlists.whitelist
|
||||
assert allowlist == allowlist_result
|
||||
|
||||
|
||||
@pytest.mark.parametrize('wildcardlist,pairs,expected', [
|
||||
(['BTC/USDT'],
|
||||
['BTC/USDT'],
|
||||
['BTC/USDT']),
|
||||
(['BTC/USDT', 'ETH/USDT'],
|
||||
['BTC/USDT', 'ETH/USDT'],
|
||||
['BTC/USDT', 'ETH/USDT']),
|
||||
(['BTC/USDT', 'ETH/USDT'],
|
||||
['BTC/USDT'], ['BTC/USDT']), # Test one too many
|
||||
(['.*/USDT'],
|
||||
['BTC/USDT', 'ETH/USDT'], ['BTC/USDT', 'ETH/USDT']), # Wildcard simple
|
||||
(['.*C/USDT'],
|
||||
['BTC/USDT', 'ETC/USDT', 'ETH/USDT'], ['BTC/USDT', 'ETC/USDT']), # Wildcard exclude one
|
||||
(['.*UP/USDT', 'BTC/USDT', 'ETH/USDT'],
|
||||
['BTC/USDT', 'ETC/USDT', 'ETH/USDT', 'BTCUP/USDT', 'XRPUP/USDT', 'XRPDOWN/USDT'],
|
||||
['BTC/USDT', 'ETH/USDT', 'BTCUP/USDT', 'XRPUP/USDT']), # Wildcard exclude one
|
||||
(['BTC/.*', 'ETH/.*'],
|
||||
['BTC/USDT', 'ETC/USDT', 'ETH/USDT', 'BTC/USD', 'ETH/EUR', 'BTC/GBP'],
|
||||
['BTC/USDT', 'ETH/USDT', 'BTC/USD', 'ETH/EUR', 'BTC/GBP']), # Wildcard exclude one
|
||||
(['*UP/USDT', 'BTC/USDT', 'ETH/USDT'],
|
||||
['BTC/USDT', 'ETC/USDT', 'ETH/USDT', 'BTCUP/USDT', 'XRPUP/USDT', 'XRPDOWN/USDT'],
|
||||
None),
|
||||
])
|
||||
def test_expand_pairlist(wildcardlist, pairs, expected):
|
||||
if expected is None:
|
||||
with pytest.raises(ValueError, match=r'Wildcard error in \*UP/USDT,'):
|
||||
expand_pairlist(wildcardlist, pairs)
|
||||
else:
|
||||
assert sorted(expand_pairlist(wildcardlist, pairs)) == sorted(expected)
|
||||
|
Loading…
Reference in New Issue
Block a user