added tests
This commit is contained in:
@@ -51,6 +51,11 @@ class RemotePairList(IPairList):
|
|||||||
self._init_done = False
|
self._init_done = False
|
||||||
self._last_pairlist: List[Any] = list()
|
self._last_pairlist: List[Any] = list()
|
||||||
|
|
||||||
|
if self._mode not in ['whitelist', 'blacklist']:
|
||||||
|
raise OperationalException(
|
||||||
|
'`mode` not configured correctly. Supported Modes '
|
||||||
|
'are "whitelist","blacklist"')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def needstickers(self) -> bool:
|
def needstickers(self) -> bool:
|
||||||
"""
|
"""
|
||||||
@@ -257,7 +262,7 @@ class RemotePairList(IPairList):
|
|||||||
if self._mode == "whitelist":
|
if self._mode == "whitelist":
|
||||||
merged_list = pairlist + rpl_pairlist
|
merged_list = pairlist + rpl_pairlist
|
||||||
merged_list = sorted(set(merged_list), key=merged_list.index)
|
merged_list = sorted(set(merged_list), key=merged_list.index)
|
||||||
elif self._mode == "blacklist":
|
else:
|
||||||
for pair in pairlist:
|
for pair in pairlist:
|
||||||
if pair not in rpl_pairlist:
|
if pair not in rpl_pairlist:
|
||||||
merged_list.append(pair)
|
merged_list.append(pair)
|
||||||
@@ -266,10 +271,5 @@ class RemotePairList(IPairList):
|
|||||||
if filtered:
|
if filtered:
|
||||||
self.log_once(f"Blacklist - Filtered out pairs: {filtered}", logger.info)
|
self.log_once(f"Blacklist - Filtered out pairs: {filtered}", logger.info)
|
||||||
|
|
||||||
else:
|
|
||||||
raise OperationalException(
|
|
||||||
'`mode` not configured correctly. Supported Modes: '
|
|
||||||
'are "whitelist","blacklist"')
|
|
||||||
|
|
||||||
merged_list = merged_list[:self._number_pairs]
|
merged_list = merged_list[:self._number_pairs]
|
||||||
return merged_list
|
return merged_list
|
||||||
|
|||||||
@@ -16,11 +16,12 @@ def rpl_config(default_conf):
|
|||||||
|
|
||||||
default_conf['exchange']['pair_whitelist'] = [
|
default_conf['exchange']['pair_whitelist'] = [
|
||||||
'ETH/USDT',
|
'ETH/USDT',
|
||||||
'BTC/USDT',
|
'XRP/USDT',
|
||||||
]
|
]
|
||||||
default_conf['exchange']['pair_blacklist'] = [
|
default_conf['exchange']['pair_blacklist'] = [
|
||||||
'BLK/USDT'
|
'BLK/USDT'
|
||||||
]
|
]
|
||||||
|
|
||||||
return default_conf
|
return default_conf
|
||||||
|
|
||||||
|
|
||||||
@@ -183,3 +184,67 @@ def test_fetch_pairlist_mock_response_valid(mocker, rpl_config):
|
|||||||
assert pairs == ["ETH/USDT", "XRP/USDT", "LTC/USDT", "EOS/USDT"]
|
assert pairs == ["ETH/USDT", "XRP/USDT", "LTC/USDT", "EOS/USDT"]
|
||||||
assert time_elapsed == 0.4
|
assert time_elapsed == 0.4
|
||||||
assert remote_pairlist._refresh_period == 60
|
assert remote_pairlist._refresh_period == 60
|
||||||
|
|
||||||
|
|
||||||
|
def test_remote_pairlist_init_wrong_mode(mocker, rpl_config):
|
||||||
|
|
||||||
|
rpl_config['pairlists'] = [
|
||||||
|
{
|
||||||
|
"method": "RemotePairList",
|
||||||
|
"mode": "blacklis",
|
||||||
|
"number_assets": 20,
|
||||||
|
"pairlist_url": "http://example.com/pairlist",
|
||||||
|
"keep_pairlist_on_failure": True,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
get_patched_exchange(mocker, rpl_config)
|
||||||
|
with pytest.raises(OperationalException, match=r'`mode` not configured correctly.'
|
||||||
|
r' Supported Modes are "whitelist","blacklist"'):
|
||||||
|
get_patched_freqtradebot(mocker, rpl_config)
|
||||||
|
|
||||||
|
|
||||||
|
def test_remote_pairlist_blacklist(mocker, rpl_config, caplog):
|
||||||
|
|
||||||
|
mock_response = MagicMock()
|
||||||
|
|
||||||
|
mock_response.json.return_value = {
|
||||||
|
"pairs": ["XRP/USDT"],
|
||||||
|
"refresh_period": 60
|
||||||
|
}
|
||||||
|
|
||||||
|
mock_response.headers = {
|
||||||
|
"content-type": "application/json"
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl_config['pairlists'] = [
|
||||||
|
{
|
||||||
|
"method": "RemotePairList",
|
||||||
|
"mode": "blacklist",
|
||||||
|
"pairlist_url": "http://example.com/pairlist",
|
||||||
|
"number_assets": 3
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
mocker.patch("freqtrade.plugins.pairlist.RemotePairList.requests.get",
|
||||||
|
return_value=mock_response)
|
||||||
|
|
||||||
|
exchange = get_patched_exchange(mocker, rpl_config)
|
||||||
|
|
||||||
|
freqtrade = get_patched_freqtradebot(mocker, rpl_config)
|
||||||
|
freqtrade.pairlists.refresh_pairlist()
|
||||||
|
whitelist = freqtrade.pairlists.whitelist
|
||||||
|
|
||||||
|
pairlistmanager = PairListManager(exchange, rpl_config)
|
||||||
|
|
||||||
|
remote_pairlist = RemotePairList(exchange, pairlistmanager, rpl_config,
|
||||||
|
rpl_config['pairlists'][0], 0)
|
||||||
|
|
||||||
|
pairs, time_elapsed = remote_pairlist.fetch_pairlist()
|
||||||
|
|
||||||
|
assert pairs == ["XRP/USDT"]
|
||||||
|
|
||||||
|
whitelist = remote_pairlist.filter_pairlist(["XRP/USDT", "ETH/USDT"], {})
|
||||||
|
assert whitelist == ["ETH/USDT"]
|
||||||
|
|
||||||
|
assert log_has(f"Blacklist - Filtered out pairs: {pairs}", caplog)
|
||||||
|
|||||||
Reference in New Issue
Block a user