mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
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
|
import logging
|
||||||
from typing import Any, Dict, List, Optional
|
from typing import Any, Dict, List, Optional
|
||||||
|
|
||||||
|
from freqtrade.exceptions import OperationalException
|
||||||
from freqtrade.plugins.pairlist.IPairList import IPairList
|
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._num_assets: int = self._pairlistconfig.get('number_assets', 0)
|
||||||
self._producer_name = self._pairlistconfig.get('producer_name', 'default')
|
self._producer_name = self._pairlistconfig.get('producer_name', 'default')
|
||||||
if config.get('external_message_consumer', {}).get('enabled') is False:
|
if not config.get('external_message_consumer', {}).get('enabled'):
|
||||||
raise ValueError("ProducerPairList requires external_message_consumer to be enabled.")
|
raise OperationalException(
|
||||||
|
"ProducerPairList requires external_message_consumer to be enabled.")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def needstickers(self) -> bool:
|
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._init', MagicMock())
|
||||||
mocker.patch('freqtrade.freqtradebot.RPCManager.send_msg', MagicMock())
|
mocker.patch('freqtrade.freqtradebot.RPCManager.send_msg', MagicMock())
|
||||||
patch_whitelist(mocker, config)
|
patch_whitelist(mocker, config)
|
||||||
|
mocker.patch('freqtrade.freqtradebot.ExternalMessageConsumer')
|
||||||
|
mocker.patch('freqtrade.configuration.config_validation._validate_consumers')
|
||||||
|
|
||||||
|
|
||||||
def get_patched_freqtradebot(mocker, config) -> FreqtradeBot:
|
def get_patched_freqtradebot(mocker, config) -> FreqtradeBot:
|
||||||
|
|
|
@ -9,6 +9,7 @@ import pytest
|
||||||
import time_machine
|
import time_machine
|
||||||
|
|
||||||
from freqtrade.constants import AVAILABLE_PAIRLISTS
|
from freqtrade.constants import AVAILABLE_PAIRLISTS
|
||||||
|
from freqtrade.data.dataprovider import DataProvider
|
||||||
from freqtrade.enums import CandleType, RunMode
|
from freqtrade.enums import CandleType, RunMode
|
||||||
from freqtrade.exceptions import OperationalException
|
from freqtrade.exceptions import OperationalException
|
||||||
from freqtrade.persistence import Trade
|
from freqtrade.persistence import Trade
|
||||||
|
@ -40,6 +41,12 @@ def whitelist_conf(default_conf):
|
||||||
"sort_key": "quoteVolume",
|
"sort_key": "quoteVolume",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
default_conf.update({
|
||||||
|
"external_message_consumer": {
|
||||||
|
"enabled": True,
|
||||||
|
"producers": [],
|
||||||
|
}
|
||||||
|
})
|
||||||
return default_conf
|
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.'}]",
|
"[{'OffsetFilter': 'OffsetFilter - Taking 10 Pairs, starting from 5.'}]",
|
||||||
None
|
None
|
||||||
),
|
),
|
||||||
|
({"method": "ProducerPairList"},
|
||||||
|
"[{'ProducerPairList': 'ProducerPairList - default'}]",
|
||||||
|
None
|
||||||
|
),
|
||||||
])
|
])
|
||||||
def test_pricefilter_desc(mocker, whitelist_conf, markets, pairlistconfig,
|
def test_pricefilter_desc(mocker, whitelist_conf, markets, pairlistconfig,
|
||||||
desc_expected, exception_expected):
|
desc_expected, exception_expected):
|
||||||
|
@ -1341,3 +1352,64 @@ def test_expand_pairlist_keep_invalid(wildcardlist, pairs, expected):
|
||||||
expand_pairlist(wildcardlist, pairs, keep_invalid=True)
|
expand_pairlist(wildcardlist, pairs, keep_invalid=True)
|
||||||
else:
|
else:
|
||||||
assert sorted(expand_pairlist(wildcardlist, pairs, keep_invalid=True)) == sorted(expected)
|
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