2018-02-12 08:37:19 +00:00
|
|
|
# pragma pylint: disable=missing-docstring,C0103,protected-access
|
2018-01-28 07:38:41 +00:00
|
|
|
|
2019-03-05 18:46:03 +00:00
|
|
|
from unittest.mock import MagicMock, PropertyMock
|
2017-12-28 14:58:02 +00:00
|
|
|
|
2019-10-28 15:13:31 +00:00
|
|
|
import pytest
|
|
|
|
|
2018-12-03 19:48:51 +00:00
|
|
|
from freqtrade.constants import AVAILABLE_PAIRLISTS
|
2020-04-25 14:29:17 +00:00
|
|
|
from freqtrade.exceptions import OperationalException
|
2019-11-09 08:31:17 +00:00
|
|
|
from freqtrade.pairlist.pairlistmanager import PairListManager
|
2020-04-25 14:29:17 +00:00
|
|
|
from freqtrade.resolvers import PairListResolver
|
|
|
|
from tests.conftest import get_patched_freqtradebot, log_has, log_has_re
|
2018-07-04 07:31:35 +00:00
|
|
|
|
2017-12-28 14:58:02 +00:00
|
|
|
|
2018-09-19 17:40:32 +00:00
|
|
|
@pytest.fixture(scope="function")
|
|
|
|
def whitelist_conf(default_conf):
|
|
|
|
default_conf['stake_currency'] = 'BTC'
|
|
|
|
default_conf['exchange']['pair_whitelist'] = [
|
2018-03-24 19:42:51 +00:00
|
|
|
'ETH/BTC',
|
|
|
|
'TKN/BTC',
|
|
|
|
'TRST/BTC',
|
|
|
|
'SWT/BTC',
|
2020-05-22 12:03:49 +00:00
|
|
|
'BCC/BTC',
|
|
|
|
'HOT/BTC',
|
2018-02-12 08:37:19 +00:00
|
|
|
]
|
2018-09-19 17:40:32 +00:00
|
|
|
default_conf['exchange']['pair_blacklist'] = [
|
2018-03-24 19:42:51 +00:00
|
|
|
'BLK/BTC'
|
2018-02-12 08:37:19 +00:00
|
|
|
]
|
2019-11-09 08:31:17 +00:00
|
|
|
default_conf['pairlists'] = [
|
|
|
|
{
|
|
|
|
"method": "VolumePairList",
|
2019-11-19 05:34:54 +00:00
|
|
|
"number_assets": 5,
|
|
|
|
"sort_key": "quoteVolume",
|
2019-11-09 08:31:17 +00:00
|
|
|
},
|
|
|
|
]
|
|
|
|
return default_conf
|
2018-02-12 08:37:19 +00:00
|
|
|
|
2019-11-09 08:31:17 +00:00
|
|
|
|
2020-05-21 09:41:00 +00:00
|
|
|
@pytest.fixture(scope="function")
|
|
|
|
def whitelist_conf_2(default_conf):
|
|
|
|
default_conf['stake_currency'] = 'BTC'
|
|
|
|
default_conf['exchange']['pair_whitelist'] = [
|
|
|
|
'ETH/BTC', 'TKN/BTC', 'BLK/BTC', 'LTC/BTC',
|
|
|
|
'BTT/BTC', 'HOT/BTC', 'FUEL/BTC', 'XRP/BTC'
|
|
|
|
]
|
|
|
|
default_conf['exchange']['pair_blacklist'] = [
|
|
|
|
'BLK/BTC'
|
|
|
|
]
|
|
|
|
default_conf['pairlists'] = [
|
|
|
|
# { "method": "StaticPairList"},
|
|
|
|
{
|
|
|
|
"method": "VolumePairList",
|
|
|
|
"number_assets": 5,
|
|
|
|
"sort_key": "quoteVolume",
|
|
|
|
"refresh_period": 0,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
return default_conf
|
|
|
|
|
|
|
|
|
2020-06-24 22:58:12 +00:00
|
|
|
@pytest.fixture(scope="function")
|
|
|
|
def whitelist_conf_3(default_conf):
|
|
|
|
default_conf['stake_currency'] = 'BTC'
|
|
|
|
default_conf['exchange']['pair_whitelist'] = [
|
|
|
|
'ETH/BTC', 'TKN/BTC', 'BLK/BTC', 'LTC/BTC',
|
|
|
|
'BTT/BTC', 'HOT/BTC', 'FUEL/BTC', 'XRP/BTC'
|
|
|
|
]
|
|
|
|
default_conf['exchange']['pair_blacklist'] = [
|
|
|
|
'BLK/BTC'
|
|
|
|
]
|
|
|
|
default_conf['pairlists'] = [
|
|
|
|
{
|
|
|
|
"method": "VolumePairList",
|
|
|
|
"number_assets": 5,
|
|
|
|
"sort_key": "quoteVolume",
|
|
|
|
"refresh_period": 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"method": "AgeFilter",
|
|
|
|
"min_days_listed": 2
|
|
|
|
}
|
|
|
|
]
|
|
|
|
return default_conf
|
|
|
|
|
|
|
|
|
2019-11-09 08:31:17 +00:00
|
|
|
@pytest.fixture(scope="function")
|
2019-11-09 08:42:34 +00:00
|
|
|
def static_pl_conf(whitelist_conf):
|
|
|
|
whitelist_conf['pairlists'] = [
|
2019-11-09 08:31:17 +00:00
|
|
|
{
|
|
|
|
"method": "StaticPairList",
|
|
|
|
},
|
|
|
|
]
|
2019-11-09 08:42:34 +00:00
|
|
|
return whitelist_conf
|
2017-12-28 14:58:02 +00:00
|
|
|
|
2017-12-28 19:05:33 +00:00
|
|
|
|
2020-04-14 18:39:54 +00:00
|
|
|
def test_log_on_refresh(mocker, static_pl_conf, markets, tickers):
|
|
|
|
mocker.patch.multiple('freqtrade.exchange.Exchange',
|
|
|
|
markets=PropertyMock(return_value=markets),
|
|
|
|
exchange_has=MagicMock(return_value=True),
|
|
|
|
get_tickers=tickers
|
|
|
|
)
|
|
|
|
freqtrade = get_patched_freqtradebot(mocker, static_pl_conf)
|
|
|
|
logmock = MagicMock()
|
|
|
|
# Assign starting whitelist
|
2020-05-19 00:35:01 +00:00
|
|
|
pl = freqtrade.pairlists._pairlist_handlers[0]
|
2020-04-14 18:39:54 +00:00
|
|
|
pl.log_on_refresh(logmock, 'Hello world')
|
|
|
|
assert logmock.call_count == 1
|
|
|
|
pl.log_on_refresh(logmock, 'Hello world')
|
|
|
|
assert logmock.call_count == 1
|
|
|
|
assert pl._log_cache.currsize == 1
|
|
|
|
assert ('Hello world',) in pl._log_cache._Cache__data
|
|
|
|
|
|
|
|
pl.log_on_refresh(logmock, 'Hello world2')
|
|
|
|
assert logmock.call_count == 2
|
|
|
|
assert pl._log_cache.currsize == 2
|
|
|
|
|
|
|
|
|
2018-12-05 19:45:11 +00:00
|
|
|
def test_load_pairlist_noexist(mocker, markets, default_conf):
|
2020-05-15 00:41:41 +00:00
|
|
|
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
2019-03-10 14:26:55 +00:00
|
|
|
mocker.patch('freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets))
|
2020-05-15 00:41:41 +00:00
|
|
|
plm = PairListManager(freqtrade.exchange, default_conf)
|
2019-07-12 20:45:49 +00:00
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r"Impossible to load Pairlist 'NonexistingPairList'. "
|
|
|
|
r"This class does not exist or contains Python code errors."):
|
2020-05-15 00:41:41 +00:00
|
|
|
PairListResolver.load_pairlist('NonexistingPairList', freqtrade.exchange, plm,
|
2019-12-23 09:03:18 +00:00
|
|
|
default_conf, {}, 1)
|
2018-12-05 19:45:11 +00:00
|
|
|
|
|
|
|
|
2019-11-09 08:31:17 +00:00
|
|
|
def test_refresh_market_pair_not_in_whitelist(mocker, markets, static_pl_conf):
|
2018-02-12 08:37:19 +00:00
|
|
|
|
2020-05-15 00:41:41 +00:00
|
|
|
freqtrade = get_patched_freqtradebot(mocker, static_pl_conf)
|
2018-02-12 08:37:19 +00:00
|
|
|
|
2019-03-05 18:46:03 +00:00
|
|
|
mocker.patch('freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets))
|
2020-05-15 00:41:41 +00:00
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
2018-01-02 12:42:10 +00:00
|
|
|
# List ordered by BaseVolume
|
2018-03-24 19:42:51 +00:00
|
|
|
whitelist = ['ETH/BTC', 'TKN/BTC']
|
2018-01-02 12:42:10 +00:00
|
|
|
# Ensure all except those in whitelist are removed
|
2020-05-15 00:41:41 +00:00
|
|
|
assert set(whitelist) == set(freqtrade.pairlists.whitelist)
|
2018-11-30 06:02:08 +00:00
|
|
|
# Ensure config dict hasn't been changed
|
2019-11-09 08:31:17 +00:00
|
|
|
assert (static_pl_conf['exchange']['pair_whitelist'] ==
|
2020-05-15 00:41:41 +00:00
|
|
|
freqtrade.config['exchange']['pair_whitelist'])
|
2017-12-28 19:05:33 +00:00
|
|
|
|
2018-01-02 12:46:16 +00:00
|
|
|
|
2019-11-09 08:42:34 +00:00
|
|
|
def test_refresh_static_pairlist(mocker, markets, static_pl_conf):
|
2020-05-15 00:41:41 +00:00
|
|
|
freqtrade = get_patched_freqtradebot(mocker, static_pl_conf)
|
2019-11-09 08:31:17 +00:00
|
|
|
mocker.patch.multiple(
|
|
|
|
'freqtrade.exchange.Exchange',
|
|
|
|
exchange_has=MagicMock(return_value=True),
|
|
|
|
markets=PropertyMock(return_value=markets),
|
|
|
|
)
|
2020-05-15 00:41:41 +00:00
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
2018-01-02 12:42:10 +00:00
|
|
|
# List ordered by BaseVolume
|
2018-03-24 19:42:51 +00:00
|
|
|
whitelist = ['ETH/BTC', 'TKN/BTC']
|
2017-12-28 14:58:02 +00:00
|
|
|
# Ensure all except those in whitelist are removed
|
2020-05-15 00:41:41 +00:00
|
|
|
assert set(whitelist) == set(freqtrade.pairlists.whitelist)
|
|
|
|
assert static_pl_conf['exchange']['pair_blacklist'] == freqtrade.pairlists.blacklist
|
2017-12-28 14:58:02 +00:00
|
|
|
|
2017-12-28 19:05:33 +00:00
|
|
|
|
2019-10-28 15:13:31 +00:00
|
|
|
def test_refresh_pairlist_dynamic(mocker, shitcoinmarkets, tickers, whitelist_conf):
|
|
|
|
|
2018-03-26 09:24:20 +00:00
|
|
|
mocker.patch.multiple(
|
2018-06-17 17:54:51 +00:00
|
|
|
'freqtrade.exchange.Exchange',
|
2018-03-26 09:24:20 +00:00
|
|
|
get_tickers=tickers,
|
2019-11-09 08:31:17 +00:00
|
|
|
exchange_has=MagicMock(return_value=True),
|
2018-03-26 09:24:20 +00:00
|
|
|
)
|
2020-05-15 00:41:41 +00:00
|
|
|
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf)
|
2019-10-28 15:13:31 +00:00
|
|
|
# Remock markets with shitcoinmarkets since get_patched_freqtradebot uses the markets fixture
|
|
|
|
mocker.patch.multiple(
|
|
|
|
'freqtrade.exchange.Exchange',
|
|
|
|
markets=PropertyMock(return_value=shitcoinmarkets),
|
2020-05-21 09:41:00 +00:00
|
|
|
)
|
2017-12-28 14:58:02 +00:00
|
|
|
# argument: use the whitelist dynamically by exchange-volume
|
2019-11-14 19:12:41 +00:00
|
|
|
whitelist = ['ETH/BTC', 'TKN/BTC', 'LTC/BTC', 'XRP/BTC', 'HOT/BTC']
|
2020-05-15 00:41:41 +00:00
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
|
|
|
assert whitelist == freqtrade.pairlists.whitelist
|
2018-02-12 08:37:19 +00:00
|
|
|
|
2020-05-21 09:41:00 +00:00
|
|
|
whitelist_conf['pairlists'] = [{'method': 'VolumePairList'}]
|
2018-12-06 18:36:33 +00:00
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r'`number_assets` not specified. Please check your configuration '
|
|
|
|
r'for "pairlist.config.number_assets"'):
|
2020-05-15 00:41:41 +00:00
|
|
|
PairListManager(freqtrade.exchange, whitelist_conf)
|
2018-12-06 18:36:33 +00:00
|
|
|
|
2017-12-28 19:05:33 +00:00
|
|
|
|
2020-05-21 09:41:00 +00:00
|
|
|
def test_refresh_pairlist_dynamic_2(mocker, shitcoinmarkets, tickers, whitelist_conf_2):
|
|
|
|
|
|
|
|
tickers_dict = tickers()
|
|
|
|
|
|
|
|
mocker.patch.multiple(
|
|
|
|
'freqtrade.exchange.Exchange',
|
|
|
|
exchange_has=MagicMock(return_value=True),
|
|
|
|
)
|
|
|
|
# Remove caching of ticker data to emulate changing volume by the time of second call
|
|
|
|
mocker.patch.multiple(
|
|
|
|
'freqtrade.pairlist.pairlistmanager.PairListManager',
|
|
|
|
_get_cached_tickers=MagicMock(return_value=tickers_dict),
|
|
|
|
)
|
|
|
|
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf_2)
|
|
|
|
# Remock markets with shitcoinmarkets since get_patched_freqtradebot uses the markets fixture
|
|
|
|
mocker.patch.multiple(
|
|
|
|
'freqtrade.exchange.Exchange',
|
|
|
|
markets=PropertyMock(return_value=shitcoinmarkets),
|
|
|
|
)
|
|
|
|
|
|
|
|
whitelist = ['ETH/BTC', 'TKN/BTC', 'LTC/BTC', 'XRP/BTC', 'HOT/BTC']
|
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
|
|
|
assert whitelist == freqtrade.pairlists.whitelist
|
|
|
|
|
|
|
|
whitelist = ['FUEL/BTC', 'ETH/BTC', 'TKN/BTC', 'LTC/BTC', 'XRP/BTC']
|
|
|
|
tickers_dict['FUEL/BTC']['quoteVolume'] = 10000.0
|
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
|
|
|
assert whitelist == freqtrade.pairlists.whitelist
|
|
|
|
|
|
|
|
|
2018-12-04 06:16:34 +00:00
|
|
|
def test_VolumePairList_refresh_empty(mocker, markets_empty, whitelist_conf):
|
2019-11-09 08:42:34 +00:00
|
|
|
mocker.patch.multiple(
|
|
|
|
'freqtrade.exchange.Exchange',
|
|
|
|
exchange_has=MagicMock(return_value=True),
|
|
|
|
)
|
2020-05-15 00:41:41 +00:00
|
|
|
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf)
|
2019-03-05 18:46:03 +00:00
|
|
|
mocker.patch('freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets_empty))
|
2018-02-12 08:37:19 +00:00
|
|
|
|
2017-12-28 14:58:02 +00:00
|
|
|
# argument: use the whitelist dynamically by exchange-volume
|
|
|
|
whitelist = []
|
2018-09-19 17:40:32 +00:00
|
|
|
whitelist_conf['exchange']['pair_whitelist'] = []
|
2020-05-15 00:41:41 +00:00
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
2018-09-19 17:40:32 +00:00
|
|
|
pairslist = whitelist_conf['exchange']['pair_whitelist']
|
2018-02-12 08:37:19 +00:00
|
|
|
|
2017-12-30 10:55:23 +00:00
|
|
|
assert set(whitelist) == set(pairslist)
|
2018-11-30 19:08:50 +00:00
|
|
|
|
|
|
|
|
2020-05-22 13:42:02 +00:00
|
|
|
@pytest.mark.parametrize("pairlists,base_currency,whitelist_result", [
|
2020-05-17 23:37:03 +00:00
|
|
|
# VolumePairList only
|
2019-11-19 05:34:54 +00:00
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"}],
|
2020-05-22 13:42:02 +00:00
|
|
|
"BTC", ['ETH/BTC', 'TKN/BTC', 'LTC/BTC', 'XRP/BTC', 'HOT/BTC']),
|
2019-11-09 14:23:36 +00:00
|
|
|
# Different sorting depending on quote or bid volume
|
2019-11-19 05:34:54 +00:00
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "bidVolume"}],
|
2020-05-22 13:42:02 +00:00
|
|
|
"BTC", ['HOT/BTC', 'FUEL/BTC', 'XRP/BTC', 'LTC/BTC', 'TKN/BTC']),
|
2019-11-19 05:34:54 +00:00
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"}],
|
2020-05-22 13:42:02 +00:00
|
|
|
"USDT", ['ETH/USDT', 'NANO/USDT', 'ADAHALF/USDT']),
|
2020-05-17 23:37:03 +00:00
|
|
|
# No pair for ETH, VolumePairList
|
2019-11-19 05:34:54 +00:00
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"}],
|
2020-05-22 13:42:02 +00:00
|
|
|
"ETH", []),
|
2020-05-17 23:37:03 +00:00
|
|
|
# No pair for ETH, StaticPairList
|
|
|
|
([{"method": "StaticPairList"}],
|
2020-05-22 13:42:02 +00:00
|
|
|
"ETH", []),
|
2020-05-17 23:37:03 +00:00
|
|
|
# No pair for ETH, all handlers
|
|
|
|
([{"method": "StaticPairList"},
|
|
|
|
{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"},
|
2020-06-24 22:58:12 +00:00
|
|
|
{"method": "AgeFilter", "min_days_listed": 2},
|
2020-05-17 23:37:03 +00:00
|
|
|
{"method": "PrecisionFilter"},
|
|
|
|
{"method": "PriceFilter", "low_price_ratio": 0.03},
|
2020-05-18 20:48:06 +00:00
|
|
|
{"method": "SpreadFilter", "max_spread_ratio": 0.005},
|
2020-05-17 23:37:03 +00:00
|
|
|
{"method": "ShuffleFilter"}],
|
2020-05-22 13:42:02 +00:00
|
|
|
"ETH", []),
|
2020-06-24 22:58:12 +00:00
|
|
|
# AgeFilter and VolumePairList (require 2 days only, all should pass age test)
|
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"},
|
|
|
|
{"method": "AgeFilter", "min_days_listed": 2}],
|
|
|
|
"BTC", ['ETH/BTC', 'TKN/BTC', 'LTC/BTC', 'XRP/BTC', 'HOT/BTC']),
|
|
|
|
# AgeFilter and VolumePairList (require 10 days, all should fail age test)
|
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"},
|
|
|
|
{"method": "AgeFilter", "min_days_listed": 10}],
|
|
|
|
"BTC", []),
|
2019-11-09 14:23:36 +00:00
|
|
|
# Precisionfilter and quote volume
|
2019-11-19 05:34:54 +00:00
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"},
|
2020-05-22 12:03:49 +00:00
|
|
|
{"method": "PrecisionFilter"}],
|
2020-05-22 13:42:02 +00:00
|
|
|
"BTC", ['ETH/BTC', 'TKN/BTC', 'LTC/BTC', 'XRP/BTC']),
|
2019-11-09 14:23:36 +00:00
|
|
|
# Precisionfilter bid
|
2019-11-19 05:34:54 +00:00
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "bidVolume"},
|
2020-05-22 12:03:49 +00:00
|
|
|
{"method": "PrecisionFilter"}],
|
2020-05-22 13:42:02 +00:00
|
|
|
"BTC", ['FUEL/BTC', 'XRP/BTC', 'LTC/BTC', 'TKN/BTC']),
|
2019-11-19 05:41:05 +00:00
|
|
|
# PriceFilter and VolumePairList
|
2019-11-19 05:34:54 +00:00
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"},
|
2019-11-19 05:41:05 +00:00
|
|
|
{"method": "PriceFilter", "low_price_ratio": 0.03}],
|
2020-05-22 13:42:02 +00:00
|
|
|
"BTC", ['ETH/BTC', 'TKN/BTC', 'LTC/BTC', 'XRP/BTC']),
|
2020-04-23 18:03:59 +00:00
|
|
|
# PriceFilter and VolumePairList
|
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"},
|
|
|
|
{"method": "PriceFilter", "low_price_ratio": 0.03}],
|
2020-05-22 13:42:02 +00:00
|
|
|
"USDT", ['ETH/USDT', 'NANO/USDT']),
|
2019-10-29 09:39:27 +00:00
|
|
|
# Hot is removed by precision_filter, Fuel by low_price_filter.
|
2019-11-14 19:12:41 +00:00
|
|
|
([{"method": "VolumePairList", "number_assets": 6, "sort_key": "quoteVolume"},
|
2019-11-09 14:23:36 +00:00
|
|
|
{"method": "PrecisionFilter"},
|
2020-05-17 23:37:03 +00:00
|
|
|
{"method": "PriceFilter", "low_price_ratio": 0.02}],
|
2020-05-22 13:42:02 +00:00
|
|
|
"BTC", ['ETH/BTC', 'TKN/BTC', 'LTC/BTC', 'XRP/BTC']),
|
2020-02-03 06:44:17 +00:00
|
|
|
# HOT and XRP are removed because below 1250 quoteVolume
|
|
|
|
([{"method": "VolumePairList", "number_assets": 5,
|
|
|
|
"sort_key": "quoteVolume", "min_value": 1250}],
|
2020-05-22 13:42:02 +00:00
|
|
|
"BTC", ['ETH/BTC', 'TKN/BTC', 'LTC/BTC']),
|
2020-05-17 23:37:03 +00:00
|
|
|
# StaticPairlist only
|
|
|
|
([{"method": "StaticPairList"}],
|
2020-05-22 13:42:02 +00:00
|
|
|
"BTC", ['ETH/BTC', 'TKN/BTC', 'HOT/BTC']),
|
2019-11-09 14:23:36 +00:00
|
|
|
# Static Pairlist before VolumePairList - sorting changes
|
|
|
|
([{"method": "StaticPairList"},
|
2020-05-17 23:37:03 +00:00
|
|
|
{"method": "VolumePairList", "number_assets": 5, "sort_key": "bidVolume"}],
|
2020-05-22 13:42:02 +00:00
|
|
|
"BTC", ['HOT/BTC', 'TKN/BTC', 'ETH/BTC']),
|
2020-02-03 06:44:17 +00:00
|
|
|
# SpreadFilter
|
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"},
|
2020-05-18 20:48:06 +00:00
|
|
|
{"method": "SpreadFilter", "max_spread_ratio": 0.005}],
|
2020-05-22 13:42:02 +00:00
|
|
|
"USDT", ['ETH/USDT']),
|
2020-05-17 23:37:03 +00:00
|
|
|
# ShuffleFilter
|
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"},
|
|
|
|
{"method": "ShuffleFilter", "seed": 77}],
|
2020-05-22 13:42:02 +00:00
|
|
|
"USDT", ['ETH/USDT', 'ADAHALF/USDT', 'NANO/USDT']),
|
2020-05-17 23:37:03 +00:00
|
|
|
# ShuffleFilter, other seed
|
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"},
|
|
|
|
{"method": "ShuffleFilter", "seed": 42}],
|
2020-05-22 13:42:02 +00:00
|
|
|
"USDT", ['NANO/USDT', 'ETH/USDT', 'ADAHALF/USDT']),
|
2020-05-17 23:37:03 +00:00
|
|
|
# ShuffleFilter, no seed
|
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"},
|
|
|
|
{"method": "ShuffleFilter"}],
|
2020-06-24 22:58:12 +00:00
|
|
|
"USDT", 3), # whitelist_result is integer -- check only length of randomized pairlist
|
|
|
|
# AgeFilter only
|
|
|
|
([{"method": "AgeFilter", "min_days_listed": 2}],
|
|
|
|
"BTC", 'filter_at_the_beginning'), # OperationalException expected
|
2020-05-22 12:03:49 +00:00
|
|
|
# PrecisionFilter after StaticPairList
|
|
|
|
([{"method": "StaticPairList"},
|
|
|
|
{"method": "PrecisionFilter"}],
|
2020-05-22 13:42:02 +00:00
|
|
|
"BTC", ['ETH/BTC', 'TKN/BTC']),
|
2020-05-22 12:03:49 +00:00
|
|
|
# PrecisionFilter only
|
|
|
|
([{"method": "PrecisionFilter"}],
|
2020-05-25 20:14:51 +00:00
|
|
|
"BTC", 'filter_at_the_beginning'), # OperationalException expected
|
2020-05-22 12:03:49 +00:00
|
|
|
# PriceFilter after StaticPairList
|
|
|
|
([{"method": "StaticPairList"},
|
|
|
|
{"method": "PriceFilter", "low_price_ratio": 0.02}],
|
2020-05-22 13:42:02 +00:00
|
|
|
"BTC", ['ETH/BTC', 'TKN/BTC']),
|
2020-05-22 12:03:49 +00:00
|
|
|
# PriceFilter only
|
|
|
|
([{"method": "PriceFilter", "low_price_ratio": 0.02}],
|
2020-05-25 20:14:51 +00:00
|
|
|
"BTC", 'filter_at_the_beginning'), # OperationalException expected
|
2020-05-22 12:03:49 +00:00
|
|
|
# ShuffleFilter after StaticPairList
|
|
|
|
([{"method": "StaticPairList"},
|
|
|
|
{"method": "ShuffleFilter", "seed": 42}],
|
2020-05-22 13:42:02 +00:00
|
|
|
"BTC", ['TKN/BTC', 'ETH/BTC', 'HOT/BTC']),
|
2020-05-22 12:03:49 +00:00
|
|
|
# ShuffleFilter only
|
|
|
|
([{"method": "ShuffleFilter", "seed": 42}],
|
2020-05-25 20:14:51 +00:00
|
|
|
"BTC", 'filter_at_the_beginning'), # OperationalException expected
|
2020-05-22 12:03:49 +00:00
|
|
|
# SpreadFilter after StaticPairList
|
|
|
|
([{"method": "StaticPairList"},
|
|
|
|
{"method": "SpreadFilter", "max_spread_ratio": 0.005}],
|
2020-05-22 13:42:02 +00:00
|
|
|
"BTC", ['ETH/BTC', 'TKN/BTC']),
|
2020-05-22 12:03:49 +00:00
|
|
|
# SpreadFilter only
|
|
|
|
([{"method": "SpreadFilter", "max_spread_ratio": 0.005}],
|
2020-05-25 20:14:51 +00:00
|
|
|
"BTC", 'filter_at_the_beginning'), # OperationalException expected
|
|
|
|
# Static Pairlist after VolumePairList, on a non-first position
|
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "bidVolume"},
|
|
|
|
{"method": "StaticPairList"}],
|
|
|
|
"BTC", 'static_in_the_middle'),
|
2019-11-09 14:23:36 +00:00
|
|
|
])
|
2019-10-28 15:13:31 +00:00
|
|
|
def test_VolumePairList_whitelist_gen(mocker, whitelist_conf, shitcoinmarkets, tickers,
|
2020-06-24 22:58:12 +00:00
|
|
|
ohlcv_history_list, pairlists, base_currency,
|
|
|
|
whitelist_result, caplog) -> None:
|
2019-11-09 14:23:36 +00:00
|
|
|
whitelist_conf['pairlists'] = pairlists
|
2020-05-15 00:59:13 +00:00
|
|
|
whitelist_conf['stake_currency'] = base_currency
|
2019-10-29 09:39:27 +00:00
|
|
|
|
2018-11-30 19:08:50 +00:00
|
|
|
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
|
2019-11-09 12:40:36 +00:00
|
|
|
|
2020-05-29 09:40:05 +00:00
|
|
|
if whitelist_result == 'static_in_the_middle':
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r"StaticPairList can only be used in the first position "
|
|
|
|
r"in the list of Pairlist Handlers."):
|
|
|
|
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf)
|
|
|
|
return
|
|
|
|
|
|
|
|
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf)
|
2019-11-09 12:40:36 +00:00
|
|
|
mocker.patch.multiple('freqtrade.exchange.Exchange',
|
|
|
|
get_tickers=tickers,
|
2020-06-24 22:58:12 +00:00
|
|
|
markets=PropertyMock(return_value=shitcoinmarkets)
|
2019-11-09 12:40:36 +00:00
|
|
|
)
|
2020-06-24 22:58:12 +00:00
|
|
|
mocker.patch.multiple(
|
|
|
|
'freqtrade.exchange.Exchange',
|
|
|
|
get_historic_ohlcv=MagicMock(return_value=ohlcv_history_list),
|
|
|
|
)
|
2018-11-30 19:08:50 +00:00
|
|
|
|
2020-05-22 13:42:02 +00:00
|
|
|
# Set whitelist_result to None if pairlist is invalid and should produce exception
|
2020-05-25 20:14:51 +00:00
|
|
|
if whitelist_result == 'filter_at_the_beginning':
|
2020-05-22 12:03:49 +00:00
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r"This Pairlist Handler should not be used at the first position "
|
|
|
|
r"in the list of Pairlist Handlers."):
|
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
2020-05-17 23:37:03 +00:00
|
|
|
else:
|
2020-05-22 12:03:49 +00:00
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
|
|
|
whitelist = freqtrade.pairlists.whitelist
|
|
|
|
|
|
|
|
assert isinstance(whitelist, list)
|
|
|
|
|
|
|
|
# Verify length of pairlist matches (used for ShuffleFilter without seed)
|
|
|
|
if type(whitelist_result) is list:
|
|
|
|
assert whitelist == whitelist_result
|
|
|
|
else:
|
|
|
|
len(whitelist) == whitelist_result
|
|
|
|
|
|
|
|
for pairlist in pairlists:
|
2020-06-24 22:58:12 +00:00
|
|
|
if pairlist['method'] == 'AgeFilter' and pairlist['min_days_listed'] and \
|
|
|
|
len(ohlcv_history_list) <= pairlist['min_days_listed']:
|
|
|
|
assert log_has_re(r'^Removed .* from whitelist, because age is less than '
|
|
|
|
r'.* day.*', caplog)
|
2020-05-22 12:03:49 +00:00
|
|
|
if pairlist['method'] == 'PrecisionFilter' and whitelist_result:
|
|
|
|
assert log_has_re(r'^Removed .* from whitelist, because stop price .* '
|
|
|
|
r'would be <= stop limit.*', caplog)
|
|
|
|
if pairlist['method'] == 'PriceFilter' and whitelist_result:
|
|
|
|
assert (log_has_re(r'^Removed .* from whitelist, because 1 unit is .*%$', caplog) or
|
|
|
|
log_has_re(r"^Removed .* from whitelist, because ticker\['last'\] "
|
|
|
|
r"is empty.*", caplog))
|
|
|
|
if pairlist['method'] == 'VolumePairList':
|
|
|
|
logmsg = ("DEPRECATED: using any key other than quoteVolume for "
|
|
|
|
"VolumePairList is deprecated.")
|
|
|
|
if pairlist['sort_key'] != 'quoteVolume':
|
|
|
|
assert log_has(logmsg, caplog)
|
|
|
|
else:
|
|
|
|
assert not log_has(logmsg, caplog)
|
2019-03-03 14:31:48 +00:00
|
|
|
|
2018-11-30 19:08:50 +00:00
|
|
|
|
|
|
|
def test_gen_pair_whitelist_not_supported(mocker, default_conf, tickers) -> None:
|
2020-05-21 09:41:00 +00:00
|
|
|
default_conf['pairlists'] = [{'method': 'VolumePairList', 'number_assets': 10}]
|
2019-11-09 12:40:36 +00:00
|
|
|
|
|
|
|
mocker.patch.multiple('freqtrade.exchange.Exchange',
|
|
|
|
get_tickers=tickers,
|
|
|
|
exchange_has=MagicMock(return_value=False),
|
|
|
|
)
|
2018-11-30 19:08:50 +00:00
|
|
|
|
2020-05-21 09:41:00 +00:00
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r'Exchange does not support dynamic whitelist.*'):
|
2018-12-03 19:00:18 +00:00
|
|
|
get_patched_freqtradebot(mocker, default_conf)
|
2018-12-03 19:48:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("pairlist", AVAILABLE_PAIRLISTS)
|
2018-12-04 06:16:34 +00:00
|
|
|
def test_pairlist_class(mocker, whitelist_conf, markets, pairlist):
|
2019-11-09 08:42:34 +00:00
|
|
|
whitelist_conf['pairlists'][0]['method'] = pairlist
|
|
|
|
mocker.patch.multiple('freqtrade.exchange.Exchange',
|
|
|
|
markets=PropertyMock(return_value=markets),
|
|
|
|
exchange_has=MagicMock(return_value=True)
|
|
|
|
)
|
2018-12-03 19:48:51 +00:00
|
|
|
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf)
|
2018-12-04 06:16:34 +00:00
|
|
|
|
2019-11-09 13:00:32 +00:00
|
|
|
assert freqtrade.pairlists.name_list == [pairlist]
|
2019-11-09 08:42:34 +00:00
|
|
|
assert pairlist in str(freqtrade.pairlists.short_desc())
|
2018-12-04 06:16:34 +00:00
|
|
|
assert isinstance(freqtrade.pairlists.whitelist, list)
|
|
|
|
assert isinstance(freqtrade.pairlists.blacklist, list)
|
|
|
|
|
|
|
|
|
2019-03-17 17:18:44 +00:00
|
|
|
@pytest.mark.parametrize("pairlist", AVAILABLE_PAIRLISTS)
|
|
|
|
@pytest.mark.parametrize("whitelist,log_message", [
|
|
|
|
(['ETH/BTC', 'TKN/BTC'], ""),
|
2019-11-12 08:27:53 +00:00
|
|
|
# TRX/ETH not in markets
|
|
|
|
(['ETH/BTC', 'TKN/BTC', 'TRX/ETH'], "is not compatible with exchange"),
|
|
|
|
# wrong stake
|
|
|
|
(['ETH/BTC', 'TKN/BTC', 'ETH/USDT'], "is not compatible with your stake currency"),
|
|
|
|
# BCH/BTC not available
|
|
|
|
(['ETH/BTC', 'TKN/BTC', 'BCH/BTC'], "is not compatible with exchange"),
|
|
|
|
# BTT/BTC is inactive
|
|
|
|
(['ETH/BTC', 'TKN/BTC', 'BTT/BTC'], "Market is not active")
|
2019-03-17 17:18:44 +00:00
|
|
|
])
|
2019-10-30 15:00:16 +00:00
|
|
|
def test__whitelist_for_active_markets(mocker, whitelist_conf, markets, pairlist, whitelist, caplog,
|
2019-11-09 12:40:36 +00:00
|
|
|
log_message, tickers):
|
|
|
|
whitelist_conf['pairlists'][0]['method'] = pairlist
|
|
|
|
mocker.patch.multiple('freqtrade.exchange.Exchange',
|
|
|
|
markets=PropertyMock(return_value=markets),
|
|
|
|
exchange_has=MagicMock(return_value=True),
|
|
|
|
get_tickers=tickers
|
|
|
|
)
|
2019-03-17 17:18:44 +00:00
|
|
|
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf)
|
|
|
|
caplog.clear()
|
2018-12-04 06:16:34 +00:00
|
|
|
|
2019-11-09 12:40:36 +00:00
|
|
|
# Assign starting whitelist
|
2020-05-19 00:35:01 +00:00
|
|
|
pairlist_handler = freqtrade.pairlists._pairlist_handlers[0]
|
|
|
|
new_whitelist = pairlist_handler._whitelist_for_active_markets(whitelist)
|
2018-12-04 06:16:34 +00:00
|
|
|
|
2019-03-17 17:18:44 +00:00
|
|
|
assert set(new_whitelist) == set(['ETH/BTC', 'TKN/BTC'])
|
|
|
|
assert log_message in caplog.text
|
2019-11-09 13:44:39 +00:00
|
|
|
|
|
|
|
|
2020-06-10 17:57:47 +00:00
|
|
|
@pytest.mark.parametrize("pairlist", AVAILABLE_PAIRLISTS)
|
|
|
|
def test__whitelist_for_active_markets_empty(mocker, whitelist_conf, markets, pairlist, tickers):
|
|
|
|
whitelist_conf['pairlists'][0]['method'] = pairlist
|
|
|
|
|
|
|
|
mocker.patch('freqtrade.exchange.Exchange.exchange_has', return_value=True)
|
|
|
|
|
|
|
|
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf)
|
|
|
|
mocker.patch.multiple('freqtrade.exchange.Exchange',
|
|
|
|
markets=PropertyMock(return_value=None),
|
|
|
|
get_tickers=tickers
|
|
|
|
)
|
|
|
|
# Assign starting whitelist
|
|
|
|
pairlist_handler = freqtrade.pairlists._pairlist_handlers[0]
|
|
|
|
with pytest.raises(OperationalException, match=r'Markets not loaded.*'):
|
|
|
|
pairlist_handler._whitelist_for_active_markets(['ETH/BTC'])
|
|
|
|
|
|
|
|
|
2019-11-09 13:44:39 +00:00
|
|
|
def test_volumepairlist_invalid_sortvalue(mocker, markets, whitelist_conf):
|
2019-11-19 05:34:54 +00:00
|
|
|
whitelist_conf['pairlists'][0].update({"sort_key": "asdf"})
|
2019-11-09 13:44:39 +00:00
|
|
|
|
|
|
|
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r"key asdf not in .*"):
|
|
|
|
get_patched_freqtradebot(mocker, whitelist_conf)
|
|
|
|
|
|
|
|
|
|
|
|
def test_volumepairlist_caching(mocker, markets, whitelist_conf, tickers):
|
|
|
|
|
|
|
|
mocker.patch.multiple('freqtrade.exchange.Exchange',
|
|
|
|
markets=PropertyMock(return_value=markets),
|
|
|
|
exchange_has=MagicMock(return_value=True),
|
|
|
|
get_tickers=tickers
|
|
|
|
)
|
2020-05-15 00:41:41 +00:00
|
|
|
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf)
|
2020-05-19 00:35:01 +00:00
|
|
|
assert freqtrade.pairlists._pairlist_handlers[0]._last_refresh == 0
|
2019-11-09 18:45:09 +00:00
|
|
|
assert tickers.call_count == 0
|
2020-05-15 00:41:41 +00:00
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
2019-11-09 18:45:09 +00:00
|
|
|
assert tickers.call_count == 1
|
2019-11-09 13:44:39 +00:00
|
|
|
|
2020-05-19 00:35:01 +00:00
|
|
|
assert freqtrade.pairlists._pairlist_handlers[0]._last_refresh != 0
|
|
|
|
lrf = freqtrade.pairlists._pairlist_handlers[0]._last_refresh
|
2020-05-15 00:41:41 +00:00
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
2019-11-09 18:45:09 +00:00
|
|
|
assert tickers.call_count == 1
|
2019-11-09 13:44:39 +00:00
|
|
|
# Time should not be updated.
|
2020-05-19 00:35:01 +00:00
|
|
|
assert freqtrade.pairlists._pairlist_handlers[0]._last_refresh == lrf
|
2019-11-09 13:49:25 +00:00
|
|
|
|
|
|
|
|
2020-06-24 22:58:12 +00:00
|
|
|
def test_agefilter_caching(mocker, markets, whitelist_conf_3, tickers, ohlcv_history_list):
|
|
|
|
|
|
|
|
mocker.patch.multiple('freqtrade.exchange.Exchange',
|
|
|
|
markets=PropertyMock(return_value=markets),
|
|
|
|
exchange_has=MagicMock(return_value=True),
|
|
|
|
get_tickers=tickers
|
|
|
|
)
|
|
|
|
mocker.patch.multiple(
|
|
|
|
'freqtrade.exchange.Exchange',
|
|
|
|
get_historic_ohlcv=MagicMock(return_value=ohlcv_history_list),
|
|
|
|
)
|
|
|
|
|
|
|
|
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf_3)
|
|
|
|
assert freqtrade.exchange.get_historic_ohlcv.call_count == 0
|
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
|
|
|
assert freqtrade.exchange.get_historic_ohlcv.call_count > 0
|
|
|
|
|
|
|
|
previous_call_count = freqtrade.exchange.get_historic_ohlcv.call_count
|
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
|
|
|
# Should not have increased since first call.
|
|
|
|
assert freqtrade.exchange.get_historic_ohlcv.call_count == previous_call_count
|
|
|
|
|
|
|
|
|
2019-11-09 13:49:25 +00:00
|
|
|
def test_pairlistmanager_no_pairlist(mocker, markets, whitelist_conf, caplog):
|
|
|
|
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
|
|
|
|
|
|
|
|
whitelist_conf['pairlists'] = []
|
|
|
|
|
|
|
|
with pytest.raises(OperationalException,
|
2020-05-19 00:35:01 +00:00
|
|
|
match=r"No Pairlist Handlers defined"):
|
2019-11-09 13:49:25 +00:00
|
|
|
get_patched_freqtradebot(mocker, whitelist_conf)
|