Add tests for Producerpairlist
This commit is contained in:
parent
1bb45a2650
commit
bd106b4b8e
@ -6,6 +6,7 @@ Provides pair list from Leader data
|
||||
import logging
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from freqtrade.exceptions import OperationalException
|
||||
from freqtrade.plugins.pairlist.IPairList import IPairList
|
||||
|
||||
|
||||
@ -34,8 +35,9 @@ class ProducerPairList(IPairList):
|
||||
|
||||
self._num_assets: int = self._pairlistconfig.get('number_assets', 0)
|
||||
self._producer_name = self._pairlistconfig.get('producer_name', 'default')
|
||||
if config.get('external_message_consumer', {}).get('enabled') is False:
|
||||
raise ValueError("ProducerPairList requires external_message_consumer to be enabled.")
|
||||
if not config.get('external_message_consumer', {}).get('enabled'):
|
||||
raise OperationalException(
|
||||
"ProducerPairList requires external_message_consumer to be enabled.")
|
||||
|
||||
@property
|
||||
def needstickers(self) -> bool:
|
||||
|
@ -200,6 +200,8 @@ def patch_freqtradebot(mocker, config) -> None:
|
||||
mocker.patch('freqtrade.freqtradebot.RPCManager._init', MagicMock())
|
||||
mocker.patch('freqtrade.freqtradebot.RPCManager.send_msg', MagicMock())
|
||||
patch_whitelist(mocker, config)
|
||||
mocker.patch('freqtrade.freqtradebot.ExternalMessageConsumer')
|
||||
mocker.patch('freqtrade.configuration.config_validation._validate_consumers')
|
||||
|
||||
|
||||
def get_patched_freqtradebot(mocker, config) -> FreqtradeBot:
|
||||
|
@ -9,6 +9,7 @@ import pytest
|
||||
import time_machine
|
||||
|
||||
from freqtrade.constants import AVAILABLE_PAIRLISTS
|
||||
from freqtrade.data.dataprovider import DataProvider
|
||||
from freqtrade.enums import CandleType, RunMode
|
||||
from freqtrade.exceptions import OperationalException
|
||||
from freqtrade.persistence import Trade
|
||||
@ -40,6 +41,12 @@ def whitelist_conf(default_conf):
|
||||
"sort_key": "quoteVolume",
|
||||
},
|
||||
]
|
||||
default_conf.update({
|
||||
"external_message_consumer": {
|
||||
"enabled": True,
|
||||
"producers": [],
|
||||
}
|
||||
})
|
||||
return default_conf
|
||||
|
||||
|
||||
@ -1167,6 +1174,10 @@ def test_spreadfilter_invalid_data(mocker, default_conf, markets, tickers, caplo
|
||||
"[{'OffsetFilter': 'OffsetFilter - Taking 10 Pairs, starting from 5.'}]",
|
||||
None
|
||||
),
|
||||
({"method": "ProducerPairList"},
|
||||
"[{'ProducerPairList': 'ProducerPairList - default'}]",
|
||||
None
|
||||
),
|
||||
])
|
||||
def test_pricefilter_desc(mocker, whitelist_conf, markets, pairlistconfig,
|
||||
desc_expected, exception_expected):
|
||||
@ -1341,3 +1352,64 @@ def test_expand_pairlist_keep_invalid(wildcardlist, pairs, expected):
|
||||
expand_pairlist(wildcardlist, pairs, keep_invalid=True)
|
||||
else:
|
||||
assert sorted(expand_pairlist(wildcardlist, pairs, keep_invalid=True)) == sorted(expected)
|
||||
|
||||
|
||||
def test_ProducerPairlist_no_emc(mocker, whitelist_conf):
|
||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
|
||||
|
||||
whitelist_conf['pairlists'] = [
|
||||
{
|
||||
"method": "ProducerPairList",
|
||||
"number_assets": 10,
|
||||
"producer_name": "hello_world",
|
||||
}
|
||||
]
|
||||
del whitelist_conf['external_message_consumer']
|
||||
|
||||
with pytest.raises(OperationalException,
|
||||
match=r"ProducerPairList requires external_message_consumer to be enabled."):
|
||||
get_patched_freqtradebot(mocker, whitelist_conf)
|
||||
|
||||
|
||||
def test_ProducerPairlist(mocker, whitelist_conf, markets):
|
||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
|
||||
mocker.patch.multiple('freqtrade.exchange.Exchange',
|
||||
markets=PropertyMock(return_value=markets),
|
||||
exchange_has=MagicMock(return_value=True),
|
||||
)
|
||||
whitelist_conf['pairlists'] = [
|
||||
{
|
||||
"method": "ProducerPairList",
|
||||
"number_assets": 2,
|
||||
"producer_name": "hello_world",
|
||||
}
|
||||
]
|
||||
whitelist_conf.update({
|
||||
"external_message_consumer": {
|
||||
"enabled": True,
|
||||
"producers": [
|
||||
{
|
||||
"name": "hello_world",
|
||||
"host": "null",
|
||||
"port": 9891,
|
||||
"ws_token": "dummy",
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
exchange = get_patched_exchange(mocker, whitelist_conf)
|
||||
dp = DataProvider(whitelist_conf, exchange, None)
|
||||
pairs = ['ETH/BTC', 'LTC/BTC', 'XRP/BTC']
|
||||
# different producer
|
||||
dp._set_producer_pairs(pairs + ['MEEP/USDT'], 'default')
|
||||
pm = PairListManager(exchange, whitelist_conf, dp)
|
||||
pm.refresh_pairlist()
|
||||
assert pm.whitelist == []
|
||||
# proper producer
|
||||
dp._set_producer_pairs(pairs, 'hello_world')
|
||||
pm.refresh_pairlist()
|
||||
|
||||
# Pairlist reduced to 2
|
||||
assert pm.whitelist == pairs[:2]
|
||||
assert len(pm.whitelist) == 2
|
||||
|
Loading…
Reference in New Issue
Block a user