2018-02-12 08:37:19 +00:00
|
|
|
# pragma pylint: disable=missing-docstring,C0103,protected-access
|
2018-01-28 07:38:41 +00:00
|
|
|
|
2021-12-14 05:23:40 +00:00
|
|
|
import logging
|
2021-04-26 09:53:33 +00:00
|
|
|
import time
|
2022-10-30 08:46:12 +00:00
|
|
|
from copy import deepcopy
|
|
|
|
from datetime import timedelta
|
2019-03-05 18:46:03 +00:00
|
|
|
from unittest.mock import MagicMock, PropertyMock
|
2017-12-28 14:58:02 +00:00
|
|
|
|
2022-02-01 18:11:51 +00:00
|
|
|
import pandas as pd
|
2019-10-28 15:13:31 +00:00
|
|
|
import pytest
|
2021-09-14 04:45:26 +00:00
|
|
|
import time_machine
|
2019-10-28 15:13:31 +00:00
|
|
|
|
2018-12-03 19:48:51 +00:00
|
|
|
from freqtrade.constants import AVAILABLE_PAIRLISTS
|
2022-09-25 08:13:00 +00:00
|
|
|
from freqtrade.data.dataprovider import DataProvider
|
2021-12-08 14:59:20 +00:00
|
|
|
from freqtrade.enums import CandleType, RunMode
|
2020-04-25 14:29:17 +00:00
|
|
|
from freqtrade.exceptions import OperationalException
|
2023-09-22 00:43:03 +00:00
|
|
|
from freqtrade.persistence import LocalTrade, Trade
|
2022-08-13 08:18:57 +00:00
|
|
|
from freqtrade.plugins.pairlist.pairlist_helpers import dynamic_expand_pairlist, expand_pairlist
|
2020-12-23 15:54:35 +00:00
|
|
|
from freqtrade.plugins.pairlistmanager import PairListManager
|
2020-04-25 14:29:17 +00:00
|
|
|
from freqtrade.resolvers import PairListResolver
|
2024-01-29 19:01:21 +00:00
|
|
|
from freqtrade.util.datetime_helpers import dt_now
|
2023-02-25 19:26:04 +00:00
|
|
|
from tests.conftest import (EXMS, create_mock_trades_usdt, get_patched_exchange,
|
|
|
|
get_patched_freqtradebot, log_has, log_has_re, num_log_has)
|
2018-07-04 07:31:35 +00:00
|
|
|
|
2017-12-28 14:58:02 +00:00
|
|
|
|
2022-12-15 18:36:21 +00:00
|
|
|
# Exclude RemotePairList from tests.
|
|
|
|
# It has a mandatory parameter, and requires special handling, which happens in test_remotepairlist.
|
|
|
|
TESTABLE_PAIRLISTS = [p for p in AVAILABLE_PAIRLISTS if p not in ['RemotePairList']]
|
|
|
|
|
|
|
|
|
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
|
|
|
},
|
|
|
|
]
|
2022-09-25 08:13:00 +00:00
|
|
|
default_conf.update({
|
|
|
|
"external_message_consumer": {
|
|
|
|
"enabled": True,
|
|
|
|
"producers": [],
|
|
|
|
}
|
|
|
|
})
|
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")
|
2020-11-21 14:51:39 +00:00
|
|
|
def whitelist_conf_agefilter(default_conf):
|
2020-06-24 22:58:12 +00:00
|
|
|
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",
|
2021-06-19 18:30:40 +00:00
|
|
|
"refresh_period": -1,
|
2020-06-24 22:58:12 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"method": "AgeFilter",
|
2021-07-03 16:58:04 +00:00
|
|
|
"min_days_listed": 2,
|
|
|
|
"max_days_listed": 100
|
2020-06-24 22:58:12 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
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-11-19 18:45:22 +00:00
|
|
|
def test_log_cached(mocker, static_pl_conf, markets, tickers):
|
2023-03-01 19:14:15 +00:00
|
|
|
mocker.patch.multiple(EXMS,
|
2020-04-14 18:39:54 +00:00
|
|
|
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-11-22 10:49:41 +00:00
|
|
|
pl.log_once('Hello world', logmock)
|
2020-04-14 18:39:54 +00:00
|
|
|
assert logmock.call_count == 1
|
2020-11-22 10:49:41 +00:00
|
|
|
pl.log_once('Hello world', logmock)
|
2020-04-14 18:39:54 +00:00
|
|
|
assert logmock.call_count == 1
|
|
|
|
assert pl._log_cache.currsize == 1
|
|
|
|
assert ('Hello world',) in pl._log_cache._Cache__data
|
|
|
|
|
2020-11-22 10:49:41 +00:00
|
|
|
pl.log_once('Hello world2', logmock)
|
2020-04-14 18:39:54 +00:00
|
|
|
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)
|
2023-02-25 19:26:04 +00:00
|
|
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value=markets))
|
2022-09-18 12:59:16 +00:00
|
|
|
plm = PairListManager(freqtrade.exchange, default_conf, MagicMock())
|
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
|
|
|
|
|
|
|
|
2021-09-29 07:15:05 +00:00
|
|
|
def test_load_pairlist_verify_multi(mocker, markets_static, default_conf):
|
2021-02-01 18:39:55 +00:00
|
|
|
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
2023-02-25 19:26:04 +00:00
|
|
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value=markets_static))
|
2022-09-18 12:59:16 +00:00
|
|
|
plm = PairListManager(freqtrade.exchange, default_conf, MagicMock())
|
2021-02-01 18:39:55 +00:00
|
|
|
# Call different versions one after the other, should always consider what was passed in
|
|
|
|
# and have no side-effects (therefore the same check multiple times)
|
|
|
|
assert plm.verify_whitelist(['ETH/BTC', 'XRP/BTC', ], print) == ['ETH/BTC', 'XRP/BTC']
|
|
|
|
assert plm.verify_whitelist(['ETH/BTC', 'XRP/BTC', 'BUUU/BTC'], print) == ['ETH/BTC', 'XRP/BTC']
|
|
|
|
assert plm.verify_whitelist(['XRP/BTC', 'BUUU/BTC'], print) == ['XRP/BTC']
|
|
|
|
assert plm.verify_whitelist(['ETH/BTC', 'XRP/BTC', ], print) == ['ETH/BTC', 'XRP/BTC']
|
|
|
|
assert plm.verify_whitelist(['ETH/USDT', 'XRP/USDT', ], print) == ['ETH/USDT', ]
|
|
|
|
assert plm.verify_whitelist(['ETH/BTC', 'XRP/BTC', ], print) == ['ETH/BTC', 'XRP/BTC']
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2023-02-25 19:26:04 +00:00
|
|
|
mocker.patch(f'{EXMS}.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(
|
2023-03-01 19:14:15 +00:00
|
|
|
EXMS,
|
2019-11-09 08:31:17 +00:00
|
|
|
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
|
|
|
|
2021-01-15 05:56:15 +00:00
|
|
|
@pytest.mark.parametrize('pairs,expected', [
|
|
|
|
(['NOEXIST/BTC', r'\+WHAT/BTC'],
|
|
|
|
['ETH/BTC', 'TKN/BTC', 'TRST/BTC', 'NOEXIST/BTC', 'SWT/BTC', 'BCC/BTC', 'HOT/BTC']),
|
|
|
|
(['NOEXIST/BTC', r'*/BTC'], # This is an invalid regex
|
|
|
|
[]),
|
|
|
|
])
|
|
|
|
def test_refresh_static_pairlist_noexist(mocker, markets, static_pl_conf, pairs, expected, caplog):
|
|
|
|
|
|
|
|
static_pl_conf['pairlists'][0]['allow_inactive'] = True
|
|
|
|
static_pl_conf['exchange']['pair_whitelist'] += pairs
|
|
|
|
freqtrade = get_patched_freqtradebot(mocker, static_pl_conf)
|
|
|
|
mocker.patch.multiple(
|
2023-03-01 19:14:15 +00:00
|
|
|
EXMS,
|
2021-01-15 05:56:15 +00:00
|
|
|
exchange_has=MagicMock(return_value=True),
|
|
|
|
markets=PropertyMock(return_value=markets),
|
|
|
|
)
|
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
|
|
|
|
|
|
|
# Ensure all except those in whitelist are removed
|
|
|
|
assert set(expected) == set(freqtrade.pairlists.whitelist)
|
|
|
|
assert static_pl_conf['exchange']['pair_blacklist'] == freqtrade.pairlists.blacklist
|
|
|
|
if not expected:
|
|
|
|
assert log_has_re(r'Pair whitelist contains an invalid Wildcard: Wildcard error.*', caplog)
|
|
|
|
|
|
|
|
|
2020-12-30 09:14:22 +00:00
|
|
|
def test_invalid_blacklist(mocker, markets, static_pl_conf, caplog):
|
|
|
|
static_pl_conf['exchange']['pair_blacklist'] = ['*/BTC']
|
|
|
|
freqtrade = get_patched_freqtradebot(mocker, static_pl_conf)
|
|
|
|
mocker.patch.multiple(
|
2023-03-01 19:14:15 +00:00
|
|
|
EXMS,
|
2020-12-30 09:14:22 +00:00
|
|
|
exchange_has=MagicMock(return_value=True),
|
|
|
|
markets=PropertyMock(return_value=markets),
|
|
|
|
)
|
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
|
|
|
whitelist = []
|
|
|
|
# Ensure all except those in whitelist are removed
|
|
|
|
assert set(whitelist) == set(freqtrade.pairlists.whitelist)
|
|
|
|
assert static_pl_conf['exchange']['pair_blacklist'] == freqtrade.pairlists.blacklist
|
|
|
|
log_has_re(r"Pair blacklist contains an invalid Wildcard.*", caplog)
|
|
|
|
|
|
|
|
|
2021-12-14 05:23:40 +00:00
|
|
|
def test_remove_logs_for_pairs_already_in_blacklist(mocker, markets, static_pl_conf, caplog):
|
2021-12-21 18:20:09 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
2021-12-14 05:23:40 +00:00
|
|
|
freqtrade = get_patched_freqtradebot(mocker, static_pl_conf)
|
|
|
|
mocker.patch.multiple(
|
2023-03-01 19:14:15 +00:00
|
|
|
EXMS,
|
2021-12-14 05:23:40 +00:00
|
|
|
exchange_has=MagicMock(return_value=True),
|
|
|
|
markets=PropertyMock(return_value=markets),
|
|
|
|
)
|
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
|
|
|
whitelist = ['ETH/BTC', 'TKN/BTC']
|
2021-12-21 18:20:09 +00:00
|
|
|
caplog.clear()
|
|
|
|
caplog.set_level(logging.INFO)
|
|
|
|
|
2021-12-14 05:23:40 +00:00
|
|
|
# Ensure all except those in whitelist are removed.
|
|
|
|
assert set(whitelist) == set(freqtrade.pairlists.whitelist)
|
|
|
|
assert static_pl_conf['exchange']['pair_blacklist'] == freqtrade.pairlists.blacklist
|
|
|
|
# Ensure that log message wasn't generated.
|
|
|
|
assert not log_has('Pair BLK/BTC in your blacklist. Removing it from whitelist...', caplog)
|
|
|
|
|
2021-12-26 20:09:25 +00:00
|
|
|
for _ in range(3):
|
|
|
|
new_whitelist = freqtrade.pairlists.verify_blacklist(
|
|
|
|
whitelist + ['BLK/BTC'], logger.warning)
|
|
|
|
# Ensure that the pair is removed from the white list, and properly logged.
|
|
|
|
assert set(whitelist) == set(new_whitelist)
|
2021-12-26 08:49:14 +00:00
|
|
|
assert num_log_has('Pair BLK/BTC in your blacklist. Removing it from whitelist...',
|
|
|
|
caplog) == 1
|
2021-12-14 05:23:40 +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(
|
2023-03-01 19:14:15 +00:00
|
|
|
EXMS,
|
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(
|
2023-03-01 19:14:15 +00:00
|
|
|
EXMS,
|
2019-10-28 15:13:31 +00:00
|
|
|
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"'):
|
2022-09-18 12:59:16 +00:00
|
|
|
PairListManager(freqtrade.exchange, whitelist_conf, MagicMock())
|
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(
|
2023-03-01 19:14:15 +00:00
|
|
|
EXMS,
|
2020-05-21 09:41:00 +00:00
|
|
|
exchange_has=MagicMock(return_value=True),
|
|
|
|
)
|
|
|
|
# Remove caching of ticker data to emulate changing volume by the time of second call
|
|
|
|
mocker.patch.multiple(
|
2020-12-23 15:54:35 +00:00
|
|
|
'freqtrade.plugins.pairlistmanager.PairListManager',
|
2020-05-21 09:41:00 +00:00
|
|
|
_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(
|
2023-03-01 19:14:15 +00:00
|
|
|
EXMS,
|
2020-05-21 09:41:00 +00:00
|
|
|
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
|
|
|
|
|
2021-04-26 09:53:33 +00:00
|
|
|
# Delay to allow 0 TTL cache to expire...
|
|
|
|
time.sleep(1)
|
2020-05-21 09:41:00 +00:00
|
|
|
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(
|
2023-03-01 19:14:15 +00:00
|
|
|
EXMS,
|
2019-11-09 08:42:34 +00:00
|
|
|
exchange_has=MagicMock(return_value=True),
|
|
|
|
)
|
2020-05-15 00:41:41 +00:00
|
|
|
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf)
|
2023-02-25 19:26:04 +00:00
|
|
|
mocker.patch(f'{EXMS}.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-19 05:34:54 +00:00
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"}],
|
2020-07-21 18:34:19 +00:00
|
|
|
"USDT", ['ETH/USDT', 'NANO/USDT', 'ADAHALF/USDT', 'ADADOUBLE/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"},
|
2021-07-03 16:58:04 +00:00
|
|
|
{"method": "AgeFilter", "min_days_listed": 2, "max_days_listed": None},
|
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-11-28 03:24:40 +00:00
|
|
|
{"method": "ShuffleFilter"}, {"method": "PerformanceFilter"}],
|
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"},
|
2021-07-03 16:58:04 +00:00
|
|
|
{"method": "AgeFilter", "min_days_listed": 2, "max_days_listed": 100}],
|
2020-06-24 22:58:12 +00:00
|
|
|
"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"},
|
2021-07-03 16:58:04 +00:00
|
|
|
{"method": "AgeFilter", "min_days_listed": 10, "max_days_listed": None}],
|
2020-06-24 22:58:12 +00:00
|
|
|
"BTC", []),
|
2021-07-03 16:58:04 +00:00
|
|
|
# AgeFilter and VolumePairList (all pair listed > 2, all should fail age test)
|
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"},
|
|
|
|
{"method": "AgeFilter", "min_days_listed": 1, "max_days_listed": 2}],
|
2020-06-24 22:58:12 +00:00
|
|
|
"BTC", []),
|
2021-07-07 18:05:56 +00:00
|
|
|
# AgeFilter and VolumePairList LTC/BTC has 6 candles - removes all
|
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"},
|
|
|
|
{"method": "AgeFilter", "min_days_listed": 4, "max_days_listed": 5}],
|
|
|
|
"BTC", []),
|
|
|
|
# AgeFilter and VolumePairList LTC/BTC has 6 candles - passes
|
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"},
|
|
|
|
{"method": "AgeFilter", "min_days_listed": 4, "max_days_listed": 10}],
|
|
|
|
"BTC", ["LTC/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']),
|
2022-08-18 18:07:41 +00:00
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"},
|
|
|
|
{"method": "PrecisionFilter"}],
|
|
|
|
"USDT", ['ETH/USDT', 'NANO/USDT']),
|
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']),
|
2020-07-08 21:02:04 +00:00
|
|
|
# Hot is removed by precision_filter, Fuel by low_price_ratio, Ripple by min_price.
|
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-07-08 21:02:04 +00:00
|
|
|
{"method": "PriceFilter", "low_price_ratio": 0.02, "min_price": 0.01}],
|
|
|
|
"BTC", ['ETH/BTC', 'TKN/BTC', 'LTC/BTC']),
|
|
|
|
# Hot is removed by precision_filter, Fuel by low_price_ratio, Ethereum by max_price.
|
|
|
|
([{"method": "VolumePairList", "number_assets": 6, "sort_key": "quoteVolume"},
|
|
|
|
{"method": "PrecisionFilter"},
|
|
|
|
{"method": "PriceFilter", "low_price_ratio": 0.02, "max_price": 0.05}],
|
|
|
|
"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
|
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-07-21 18:34:19 +00:00
|
|
|
"USDT", ['ADADOUBLE/USDT', 'ETH/USDT', 'NANO/USDT', 'ADAHALF/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-07-21 18:34:19 +00:00
|
|
|
"USDT", ['ADAHALF/USDT', 'NANO/USDT', 'ADADOUBLE/USDT', 'ETH/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"},
|
2020-07-08 21:02:04 +00:00
|
|
|
{"method": "PriceFilter", "low_price_ratio": 0.02, "min_price": 0.000001, "max_price": 0.1}],
|
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-11-29 16:30:43 +00:00
|
|
|
# PerformanceFilter after StaticPairList
|
2020-11-28 03:24:40 +00:00
|
|
|
([{"method": "StaticPairList"},
|
2020-11-28 06:39:18 +00:00
|
|
|
{"method": "PerformanceFilter"}],
|
2020-11-28 07:34:40 +00:00
|
|
|
"BTC", ['ETH/BTC', 'TKN/BTC', 'HOT/BTC']),
|
2020-11-28 06:38:06 +00:00
|
|
|
# PerformanceFilter only
|
2020-11-28 06:39:18 +00:00
|
|
|
([{"method": "PerformanceFilter"}],
|
2020-11-28 23:17:40 +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
|
2021-10-19 17:48:56 +00:00
|
|
|
# Static Pairlist after VolumePairList, on a non-first position (appends pairs)
|
|
|
|
([{"method": "VolumePairList", "number_assets": 2, "sort_key": "quoteVolume"},
|
2020-09-01 08:31:11 +00:00
|
|
|
{"method": "StaticPairList"}],
|
2021-10-19 17:48:56 +00:00
|
|
|
"BTC", ['ETH/BTC', 'TKN/BTC', 'TRST/BTC', 'SWT/BTC', 'BCC/BTC', 'HOT/BTC']),
|
2020-07-21 18:34:19 +00:00
|
|
|
([{"method": "VolumePairList", "number_assets": 20, "sort_key": "quoteVolume"},
|
|
|
|
{"method": "PriceFilter", "low_price_ratio": 0.02}],
|
|
|
|
"USDT", ['ETH/USDT', 'NANO/USDT']),
|
2021-05-17 04:47:58 +00:00
|
|
|
([{"method": "VolumePairList", "number_assets": 20, "sort_key": "quoteVolume"},
|
|
|
|
{"method": "PriceFilter", "max_value": 0.000001}],
|
|
|
|
"USDT", ['NANO/USDT']),
|
2020-11-21 14:39:04 +00:00
|
|
|
([{"method": "StaticPairList"},
|
2020-11-22 18:47:27 +00:00
|
|
|
{"method": "RangeStabilityFilter", "lookback_days": 10,
|
2021-08-02 05:15:09 +00:00
|
|
|
"min_rate_of_change": 0.01, "refresh_period": 1440}],
|
2020-11-21 14:39:04 +00:00
|
|
|
"BTC", ['ETH/BTC', 'TKN/BTC', 'HOT/BTC']),
|
2021-08-02 05:15:09 +00:00
|
|
|
([{"method": "StaticPairList"},
|
|
|
|
{"method": "RangeStabilityFilter", "lookback_days": 10,
|
|
|
|
"max_rate_of_change": 0.01, "refresh_period": 1440}],
|
|
|
|
"BTC", []), # All removed because of max_rate_of_change being 0.017
|
2022-09-21 04:51:14 +00:00
|
|
|
([{"method": "StaticPairList"},
|
|
|
|
{"method": "RangeStabilityFilter", "lookback_days": 10,
|
|
|
|
"min_rate_of_change": 0.018, "max_rate_of_change": 0.02, "refresh_period": 1440}],
|
|
|
|
"BTC", []), # All removed - limits are above the highest change_rate
|
2021-04-06 20:41:15 +00:00
|
|
|
([{"method": "StaticPairList"},
|
|
|
|
{"method": "VolatilityFilter", "lookback_days": 3,
|
|
|
|
"min_volatility": 0.002, "max_volatility": 0.004, "refresh_period": 1440}],
|
2021-07-07 10:06:55 +00:00
|
|
|
"BTC", ['ETH/BTC', 'TKN/BTC']),
|
|
|
|
# VolumePairList with no offset = unchanged pairlist
|
|
|
|
([{"method": "VolumePairList", "number_assets": 20, "sort_key": "quoteVolume"},
|
2022-05-14 12:14:53 +00:00
|
|
|
{"method": "OffsetFilter", "offset": 0, "number_assets": 0}],
|
2021-07-07 10:06:55 +00:00
|
|
|
"USDT", ['ETH/USDT', 'NANO/USDT', 'ADAHALF/USDT', 'ADADOUBLE/USDT']),
|
|
|
|
# VolumePairList with offset = 2
|
|
|
|
([{"method": "VolumePairList", "number_assets": 20, "sort_key": "quoteVolume"},
|
|
|
|
{"method": "OffsetFilter", "offset": 2}],
|
|
|
|
"USDT", ['ADAHALF/USDT', 'ADADOUBLE/USDT']),
|
2022-05-14 12:14:53 +00:00
|
|
|
# VolumePairList with offset and limit
|
|
|
|
([{"method": "VolumePairList", "number_assets": 20, "sort_key": "quoteVolume"},
|
|
|
|
{"method": "OffsetFilter", "offset": 1, "number_assets": 2}],
|
|
|
|
"USDT", ['NANO/USDT', 'ADAHALF/USDT']),
|
2021-07-07 10:06:55 +00:00
|
|
|
# VolumePairList with higher offset, than total pairlist
|
|
|
|
([{"method": "VolumePairList", "number_assets": 20, "sort_key": "quoteVolume"},
|
|
|
|
{"method": "OffsetFilter", "offset": 100}],
|
|
|
|
"USDT", [])
|
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-12-15 19:49:46 +00:00
|
|
|
ohlcv_history, pairlists, base_currency,
|
2020-06-24 22:58:12 +00:00
|
|
|
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
|
|
|
|
2021-04-06 20:41:15 +00:00
|
|
|
ohlcv_history_high_vola = ohlcv_history.copy()
|
2021-04-06 21:11:40 +00:00
|
|
|
ohlcv_history_high_vola.loc[ohlcv_history_high_vola.index == 1, 'close'] = 0.00090
|
2021-04-06 20:41:15 +00:00
|
|
|
|
2020-12-15 19:49:46 +00:00
|
|
|
ohlcv_data = {
|
2021-12-08 13:35:15 +00:00
|
|
|
('ETH/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
|
|
|
('TKN/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
2022-02-11 16:02:04 +00:00
|
|
|
('LTC/BTC', '1d', CandleType.SPOT): pd.concat([ohlcv_history, ohlcv_history]),
|
2021-12-08 13:35:15 +00:00
|
|
|
('XRP/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
|
|
|
('HOT/BTC', '1d', CandleType.SPOT): ohlcv_history_high_vola,
|
2020-12-15 19:49:46 +00:00
|
|
|
}
|
|
|
|
|
2023-02-25 19:26:04 +00:00
|
|
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
2019-11-09 12:40:36 +00:00
|
|
|
|
2020-05-29 09:40:05 +00:00
|
|
|
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf)
|
2023-03-01 19:14:15 +00:00
|
|
|
mocker.patch.multiple(EXMS,
|
2019-11-09 12:40:36 +00:00
|
|
|
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(
|
2023-03-01 19:14:15 +00:00
|
|
|
EXMS,
|
2020-12-15 19:49:46 +00:00
|
|
|
refresh_latest_ohlcv=MagicMock(return_value=ohlcv_data),
|
2020-06-24 22:58:12 +00:00
|
|
|
)
|
2018-11-30 19:08:50 +00:00
|
|
|
|
2020-11-28 06:24:48 +00:00
|
|
|
# Provide for PerformanceFilter's dependency
|
|
|
|
mocker.patch.multiple('freqtrade.persistence.Trade',
|
2020-11-28 15:45:17 +00:00
|
|
|
get_overall_performance=MagicMock(return_value=[])
|
2020-11-28 07:49:46 +00:00
|
|
|
)
|
2020-11-28 06:24:48 +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)
|
2023-08-22 18:39:36 +00:00
|
|
|
if isinstance(whitelist_result, list):
|
2020-05-22 12:03:49 +00:00
|
|
|
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 \
|
2021-07-03 16:58:04 +00:00
|
|
|
len(ohlcv_history) < pairlist['min_days_listed']:
|
2020-07-02 09:38:38 +00:00
|
|
|
assert log_has_re(r'^Removed .* from whitelist, because age .* is less than '
|
2020-06-24 22:58:12 +00:00
|
|
|
r'.* day.*', caplog)
|
2021-07-03 16:58:04 +00:00
|
|
|
if pairlist['method'] == 'AgeFilter' and pairlist['max_days_listed'] and \
|
|
|
|
len(ohlcv_history) > pairlist['max_days_listed']:
|
|
|
|
assert log_has_re(r'^Removed .* from whitelist, because age .* is less than '
|
|
|
|
r'.* day.* or more than .* 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
|
2020-07-08 21:02:04 +00:00
|
|
|
log_has_re(r'^Removed .* from whitelist, '
|
|
|
|
r'because last price < .*%$', caplog) or
|
|
|
|
log_has_re(r'^Removed .* from whitelist, '
|
|
|
|
r'because last price > .*%$', caplog) or
|
2021-05-17 04:47:58 +00:00
|
|
|
log_has_re(r'^Removed .* from whitelist, '
|
|
|
|
r'because min value change of .*', caplog) or
|
2020-05-22 12:03:49 +00:00
|
|
|
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)
|
2021-04-06 20:41:15 +00:00
|
|
|
if pairlist["method"] == 'VolatilityFilter':
|
|
|
|
assert log_has_re(r'^Removed .* from whitelist, because volatility.*$', caplog)
|
2018-11-30 19:08:50 +00:00
|
|
|
|
2021-04-06 21:11:40 +00:00
|
|
|
|
2022-01-06 15:25:01 +00:00
|
|
|
@pytest.mark.parametrize("pairlists,base_currency,exchange,volumefilter_result", [
|
2021-07-05 18:59:27 +00:00
|
|
|
# default refresh of 1800 to small for daily candle lookback
|
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume",
|
|
|
|
"lookback_days": 1}],
|
2022-01-06 15:25:01 +00:00
|
|
|
"BTC", "binance", "default_refresh_too_short"), # OperationalException expected
|
2021-07-05 18:59:27 +00:00
|
|
|
# ambigous configuration with lookback days and period
|
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume",
|
|
|
|
"lookback_days": 1, "lookback_period": 1}],
|
2022-01-06 15:25:01 +00:00
|
|
|
"BTC", "binance", "lookback_days_and_period"), # OperationalException expected
|
2021-07-05 18:59:27 +00:00
|
|
|
# negative lookback period
|
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume",
|
|
|
|
"lookback_timeframe": "1d", "lookback_period": -1}],
|
2022-01-06 15:25:01 +00:00
|
|
|
"BTC", "binance", "lookback_period_negative"), # OperationalException expected
|
2021-07-05 18:59:27 +00:00
|
|
|
# lookback range exceedes exchange limit
|
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume",
|
|
|
|
"lookback_timeframe": "1m", "lookback_period": 2000, "refresh_period": 3600}],
|
2022-01-06 15:25:01 +00:00
|
|
|
"BTC", "binance", "lookback_exceeds_exchange_request_size"), # OperationalException expected
|
2021-07-05 18:59:27 +00:00
|
|
|
# expecing pairs as given
|
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume",
|
|
|
|
"lookback_timeframe": "1d", "lookback_period": 1, "refresh_period": 86400}],
|
2022-01-06 15:25:01 +00:00
|
|
|
"BTC", "binance", ['LTC/BTC', 'ETH/BTC', 'TKN/BTC', 'XRP/BTC', 'HOT/BTC']),
|
2022-03-17 19:11:56 +00:00
|
|
|
# expecting pairs as input, because 1h candles are not available
|
2021-07-05 18:59:27 +00:00
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume",
|
|
|
|
"lookback_timeframe": "1h", "lookback_period": 2, "refresh_period": 3600}],
|
2022-03-17 19:11:56 +00:00
|
|
|
"BTC", "binance", ['ETH/BTC', 'LTC/BTC', 'NEO/BTC', 'TKN/BTC', 'XRP/BTC']),
|
2023-09-06 17:34:40 +00:00
|
|
|
# TKN/BTC is removed because it doesn't have enough candles
|
|
|
|
([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume",
|
|
|
|
"lookback_timeframe": "1d", "lookback_period": 6, "refresh_period": 86400}],
|
|
|
|
"BTC", "binance", ['LTC/BTC', 'XRP/BTC', 'ETH/BTC', 'HOT/BTC', 'NEO/BTC']),
|
2024-02-15 05:42:57 +00:00
|
|
|
# VolumePairlist in range mode as filter.
|
|
|
|
# TKN/BTC is removed because it doesn't have enough candles
|
|
|
|
([{"method": "VolumePairList", "number_assets": 5},
|
|
|
|
{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume",
|
|
|
|
"lookback_timeframe": "1d", "lookback_period": 2, "refresh_period": 86400}],
|
|
|
|
"BTC", "binance", ['LTC/BTC', 'XRP/BTC', 'ETH/BTC', 'TKN/BTC', 'HOT/BTC']),
|
2022-01-06 15:25:01 +00:00
|
|
|
# ftx data is already in Quote currency, therefore won't require conversion
|
2022-11-14 18:40:57 +00:00
|
|
|
# ([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume",
|
|
|
|
# "lookback_timeframe": "1d", "lookback_period": 1, "refresh_period": 86400}],
|
|
|
|
# "BTC", "ftx", ['HOT/BTC', 'LTC/BTC', 'ETH/BTC', 'TKN/BTC', 'XRP/BTC']),
|
2021-07-05 18:59:27 +00:00
|
|
|
])
|
2024-02-15 05:39:07 +00:00
|
|
|
def test_VolumePairList_range(
|
|
|
|
mocker, whitelist_conf, shitcoinmarkets, tickers, ohlcv_history,
|
|
|
|
pairlists, base_currency, exchange, volumefilter_result, time_machine) -> None:
|
2021-07-05 18:59:27 +00:00
|
|
|
whitelist_conf['pairlists'] = pairlists
|
|
|
|
whitelist_conf['stake_currency'] = base_currency
|
2022-01-06 15:25:01 +00:00
|
|
|
whitelist_conf['exchange']['name'] = exchange
|
2023-09-06 17:34:40 +00:00
|
|
|
# Ensure we have 6 candles
|
|
|
|
ohlcv_history_long = pd.concat([ohlcv_history, ohlcv_history])
|
2021-07-05 18:59:27 +00:00
|
|
|
|
2023-09-06 17:34:40 +00:00
|
|
|
ohlcv_history_high_vola = ohlcv_history_long.copy()
|
2021-07-05 18:59:27 +00:00
|
|
|
ohlcv_history_high_vola.loc[ohlcv_history_high_vola.index == 1, 'close'] = 0.00090
|
|
|
|
|
2021-07-07 09:28:35 +00:00
|
|
|
# create candles for medium overall volume with last candle high volume
|
2023-09-06 17:34:40 +00:00
|
|
|
ohlcv_history_medium_volume = ohlcv_history_long.copy()
|
2021-07-07 09:28:35 +00:00
|
|
|
ohlcv_history_medium_volume.loc[ohlcv_history_medium_volume.index == 2, 'volume'] = 5
|
|
|
|
|
2022-01-06 15:25:01 +00:00
|
|
|
# create candles for high volume with all candles high volume, but very low price.
|
2023-09-06 17:34:40 +00:00
|
|
|
ohlcv_history_high_volume = ohlcv_history_long.copy()
|
2022-09-27 08:10:58 +00:00
|
|
|
ohlcv_history_high_volume['volume'] = 10
|
|
|
|
ohlcv_history_high_volume['low'] = ohlcv_history_high_volume.loc[:, 'low'] * 0.01
|
|
|
|
ohlcv_history_high_volume['high'] = ohlcv_history_high_volume.loc[:, 'high'] * 0.01
|
|
|
|
ohlcv_history_high_volume['close'] = ohlcv_history_high_volume.loc[:, 'close'] * 0.01
|
2022-01-06 15:25:01 +00:00
|
|
|
|
2021-07-05 18:59:27 +00:00
|
|
|
ohlcv_data = {
|
2023-09-06 17:34:40 +00:00
|
|
|
('ETH/BTC', '1d', CandleType.SPOT): ohlcv_history_long,
|
2021-12-08 13:35:15 +00:00
|
|
|
('TKN/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
|
|
|
('LTC/BTC', '1d', CandleType.SPOT): ohlcv_history_medium_volume,
|
|
|
|
('XRP/BTC', '1d', CandleType.SPOT): ohlcv_history_high_vola,
|
|
|
|
('HOT/BTC', '1d', CandleType.SPOT): ohlcv_history_high_volume,
|
2021-07-05 18:59:27 +00:00
|
|
|
}
|
|
|
|
|
2023-02-25 19:26:04 +00:00
|
|
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
2021-07-05 18:59:27 +00:00
|
|
|
|
|
|
|
if volumefilter_result == 'default_refresh_too_short':
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r'Refresh period of [0-9]+ seconds is smaller than one timeframe '
|
|
|
|
r'of [0-9]+.*\. Please adjust refresh_period to at least [0-9]+ '
|
|
|
|
r'and restart the bot\.'):
|
|
|
|
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf)
|
|
|
|
return
|
|
|
|
elif volumefilter_result == 'lookback_days_and_period':
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r'Ambigous configuration: lookback_days and lookback_period both '
|
|
|
|
r'set in pairlist config\..*'):
|
|
|
|
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf)
|
|
|
|
elif volumefilter_result == 'lookback_period_negative':
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r'VolumeFilter requires lookback_period to be >= 0'):
|
|
|
|
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf)
|
|
|
|
elif volumefilter_result == 'lookback_exceeds_exchange_request_size':
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r'VolumeFilter requires lookback_period to not exceed '
|
|
|
|
r'exchange max request size \([0-9]+\)'):
|
|
|
|
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf)
|
|
|
|
else:
|
|
|
|
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf)
|
|
|
|
mocker.patch.multiple(
|
2023-03-01 19:14:15 +00:00
|
|
|
EXMS,
|
2021-07-05 18:59:27 +00:00
|
|
|
get_tickers=tickers,
|
|
|
|
markets=PropertyMock(return_value=shitcoinmarkets)
|
|
|
|
)
|
2024-02-15 05:39:07 +00:00
|
|
|
start_dt = dt_now()
|
|
|
|
time_machine.move_to(start_dt)
|
2021-07-05 18:59:27 +00:00
|
|
|
# remove ohlcv when looback_timeframe != 1d
|
|
|
|
# to enforce fallback to ticker data
|
|
|
|
if 'lookback_timeframe' in pairlists[0]:
|
|
|
|
if pairlists[0]['lookback_timeframe'] != '1d':
|
2024-02-15 05:42:57 +00:00
|
|
|
ohlcv_data = {}
|
2021-07-05 18:59:27 +00:00
|
|
|
|
2024-02-15 05:39:07 +00:00
|
|
|
ohclv_mock = mocker.patch(f"{EXMS}.refresh_latest_ohlcv", return_value=ohlcv_data)
|
2021-07-05 18:59:27 +00:00
|
|
|
|
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
|
|
|
whitelist = freqtrade.pairlists.whitelist
|
2024-02-15 05:39:07 +00:00
|
|
|
assert ohclv_mock.call_count == 1
|
2021-07-05 18:59:27 +00:00
|
|
|
|
|
|
|
assert isinstance(whitelist, list)
|
|
|
|
assert whitelist == volumefilter_result
|
2024-02-15 05:39:07 +00:00
|
|
|
# Test caching
|
|
|
|
ohclv_mock.reset_mock()
|
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
2024-02-15 05:42:57 +00:00
|
|
|
# in "filter" mode, caching is disabled.
|
2024-02-15 17:16:55 +00:00
|
|
|
assert ohclv_mock.call_count == 0
|
2024-02-15 05:39:07 +00:00
|
|
|
whitelist = freqtrade.pairlists.whitelist
|
|
|
|
assert whitelist == volumefilter_result
|
|
|
|
|
|
|
|
time_machine.move_to(start_dt + timedelta(days=2))
|
|
|
|
ohclv_mock.reset_mock()
|
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
|
|
|
assert ohclv_mock.call_count == 1
|
|
|
|
whitelist = freqtrade.pairlists.whitelist
|
|
|
|
assert whitelist == volumefilter_result
|
2021-07-05 18:59:27 +00:00
|
|
|
|
|
|
|
|
2020-11-28 04:18:49 +00:00
|
|
|
def test_PrecisionFilter_error(mocker, whitelist_conf) -> None:
|
2020-06-09 12:33:57 +00:00
|
|
|
whitelist_conf['pairlists'] = [{"method": "StaticPairList"}, {"method": "PrecisionFilter"}]
|
|
|
|
del whitelist_conf['stoploss']
|
|
|
|
|
2023-02-25 19:26:04 +00:00
|
|
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
2020-06-09 12:33:57 +00:00
|
|
|
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r"PrecisionFilter can only work with stoploss defined\..*"):
|
2022-09-18 12:59:16 +00:00
|
|
|
PairListManager(MagicMock, whitelist_conf, MagicMock())
|
2020-06-09 12:33:57 +00:00
|
|
|
|
|
|
|
|
2021-05-16 17:55:13 +00:00
|
|
|
def test_PerformanceFilter_error(mocker, whitelist_conf, caplog) -> None:
|
|
|
|
whitelist_conf['pairlists'] = [{"method": "StaticPairList"}, {"method": "PerformanceFilter"}]
|
2023-03-16 17:07:06 +00:00
|
|
|
if hasattr(Trade, 'session'):
|
|
|
|
del Trade.session
|
2023-02-25 19:26:04 +00:00
|
|
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
2021-05-16 17:55:13 +00:00
|
|
|
exchange = get_patched_exchange(mocker, whitelist_conf)
|
2022-09-18 12:59:16 +00:00
|
|
|
pm = PairListManager(exchange, whitelist_conf, MagicMock())
|
2021-05-16 17:55:13 +00:00
|
|
|
pm.refresh_pairlist()
|
|
|
|
|
|
|
|
assert log_has("PerformanceFilter is not available in this mode.", caplog)
|
|
|
|
|
|
|
|
|
2024-02-24 12:20:59 +00:00
|
|
|
def test_VolatilityFilter_error(mocker, whitelist_conf) -> None:
|
|
|
|
volatility_filter = {"method": "VolatilityFilter", "lookback_days": -1}
|
|
|
|
whitelist_conf['pairlists'] = [{"method": "StaticPairList"}, volatility_filter]
|
|
|
|
|
|
|
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
|
|
|
exchange_mock = MagicMock()
|
|
|
|
exchange_mock.ohlcv_candle_limit = MagicMock(return_value=1000)
|
|
|
|
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r"VolatilityFilter requires lookback_days to be >= 1*"):
|
|
|
|
PairListManager(exchange_mock, whitelist_conf, MagicMock())
|
|
|
|
|
|
|
|
volatility_filter = {"method": "VolatilityFilter", "lookback_days": 2000}
|
|
|
|
whitelist_conf['pairlists'] = [{"method": "StaticPairList"}, volatility_filter]
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r"VolatilityFilter requires lookback_days to not exceed exchange max"):
|
|
|
|
PairListManager(exchange_mock, whitelist_conf, MagicMock())
|
|
|
|
|
|
|
|
volatility_filter = {"method": "VolatilityFilter", "sort_direction": "Random"}
|
|
|
|
whitelist_conf['pairlists'] = [{"method": "StaticPairList"}, volatility_filter]
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r"VolatilityFilter requires sort_direction to be either "
|
|
|
|
r"None .*'asc'.*'desc'"):
|
|
|
|
PairListManager(exchange_mock, whitelist_conf, MagicMock())
|
|
|
|
|
|
|
|
|
2021-11-27 18:41:36 +00:00
|
|
|
def test_ShuffleFilter_init(mocker, whitelist_conf, caplog) -> None:
|
|
|
|
whitelist_conf['pairlists'] = [
|
|
|
|
{"method": "StaticPairList"},
|
2022-10-30 08:46:12 +00:00
|
|
|
{"method": "ShuffleFilter", "seed": 43}
|
2021-11-27 18:41:36 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
exchange = get_patched_exchange(mocker, whitelist_conf)
|
2022-10-30 08:46:12 +00:00
|
|
|
plm = PairListManager(exchange, whitelist_conf)
|
|
|
|
assert log_has("Backtesting mode detected, applying seed value: 43", caplog)
|
|
|
|
|
|
|
|
with time_machine.travel("2021-09-01 05:01:00 +00:00") as t:
|
|
|
|
plm.refresh_pairlist()
|
|
|
|
pl1 = deepcopy(plm.whitelist)
|
|
|
|
plm.refresh_pairlist()
|
|
|
|
assert plm.whitelist == pl1
|
|
|
|
|
|
|
|
t.shift(timedelta(minutes=10))
|
|
|
|
plm.refresh_pairlist()
|
|
|
|
assert plm.whitelist != pl1
|
|
|
|
|
2021-11-27 18:41:36 +00:00
|
|
|
caplog.clear()
|
|
|
|
whitelist_conf['runmode'] = RunMode.DRY_RUN
|
2022-10-30 08:46:12 +00:00
|
|
|
plm = PairListManager(exchange, whitelist_conf)
|
2021-11-27 18:41:36 +00:00
|
|
|
assert not log_has("Backtesting mode detected, applying seed value: 42", caplog)
|
|
|
|
assert log_has("Live mode detected, not applying seed.", caplog)
|
|
|
|
|
|
|
|
|
2021-09-19 23:44:12 +00:00
|
|
|
@pytest.mark.usefixtures("init_persistence")
|
2022-02-06 15:03:14 +00:00
|
|
|
def test_PerformanceFilter_lookback(mocker, default_conf_usdt, fee, caplog) -> None:
|
|
|
|
default_conf_usdt['exchange']['pair_whitelist'].extend(['ADA/USDT', 'XRP/USDT', 'ETC/USDT'])
|
|
|
|
default_conf_usdt['pairlists'] = [
|
2021-09-19 23:44:12 +00:00
|
|
|
{"method": "StaticPairList"},
|
2021-10-14 17:33:32 +00:00
|
|
|
{"method": "PerformanceFilter", "minutes": 60, "min_profit": 0.01}
|
2021-09-19 23:44:12 +00:00
|
|
|
]
|
2023-02-25 19:26:04 +00:00
|
|
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
2022-02-06 15:03:14 +00:00
|
|
|
exchange = get_patched_exchange(mocker, default_conf_usdt)
|
|
|
|
pm = PairListManager(exchange, default_conf_usdt)
|
2021-09-19 23:44:12 +00:00
|
|
|
pm.refresh_pairlist()
|
|
|
|
|
2022-02-06 15:03:14 +00:00
|
|
|
assert pm.whitelist == ['ETH/USDT', 'XRP/USDT', 'NEO/USDT', 'TKN/USDT']
|
2021-09-19 23:44:12 +00:00
|
|
|
|
|
|
|
with time_machine.travel("2021-09-01 05:00:00 +00:00") as t:
|
2022-02-06 15:03:14 +00:00
|
|
|
create_mock_trades_usdt(fee)
|
2021-09-19 23:44:12 +00:00
|
|
|
pm.refresh_pairlist()
|
2022-08-16 08:59:43 +00:00
|
|
|
assert pm.whitelist == ['XRP/USDT', 'NEO/USDT']
|
2021-10-14 17:33:32 +00:00
|
|
|
assert log_has_re(r'Removing pair .* since .* is below .*', caplog)
|
2021-09-19 23:44:12 +00:00
|
|
|
|
|
|
|
# Move to "outside" of lookback window, so original sorting is restored.
|
|
|
|
t.move_to("2021-09-01 07:00:00 +00:00")
|
|
|
|
pm.refresh_pairlist()
|
2022-02-06 15:03:14 +00:00
|
|
|
assert pm.whitelist == ['ETH/USDT', 'XRP/USDT', 'NEO/USDT', 'TKN/USDT']
|
|
|
|
|
|
|
|
|
2022-02-06 15:19:11 +00:00
|
|
|
@pytest.mark.usefixtures("init_persistence")
|
|
|
|
def test_PerformanceFilter_keep_mid_order(mocker, default_conf_usdt, fee, caplog) -> None:
|
|
|
|
default_conf_usdt['exchange']['pair_whitelist'].extend(['ADA/USDT', 'ETC/USDT'])
|
|
|
|
default_conf_usdt['pairlists'] = [
|
|
|
|
{"method": "StaticPairList", "allow_inactive": True},
|
|
|
|
{"method": "PerformanceFilter", "minutes": 60, }
|
|
|
|
]
|
2023-02-25 19:26:04 +00:00
|
|
|
mocker.patch(f'{EXMS}.exchange_has', return_value=True)
|
2022-02-06 15:19:11 +00:00
|
|
|
exchange = get_patched_exchange(mocker, default_conf_usdt)
|
|
|
|
pm = PairListManager(exchange, default_conf_usdt)
|
|
|
|
pm.refresh_pairlist()
|
|
|
|
|
|
|
|
assert pm.whitelist == ['ETH/USDT', 'LTC/USDT', 'XRP/USDT',
|
|
|
|
'NEO/USDT', 'TKN/USDT', 'ADA/USDT', 'ETC/USDT']
|
|
|
|
|
|
|
|
with time_machine.travel("2021-09-01 05:00:00 +00:00") as t:
|
|
|
|
create_mock_trades_usdt(fee)
|
|
|
|
pm.refresh_pairlist()
|
2022-08-16 08:59:43 +00:00
|
|
|
assert pm.whitelist == ['XRP/USDT', 'NEO/USDT', 'ETH/USDT', 'LTC/USDT',
|
|
|
|
'TKN/USDT', 'ADA/USDT', 'ETC/USDT', ]
|
2022-02-06 15:19:11 +00:00
|
|
|
# assert log_has_re(r'Removing pair .* since .* is below .*', caplog)
|
|
|
|
|
|
|
|
# Move to "outside" of lookback window, so original sorting is restored.
|
|
|
|
t.move_to("2021-09-01 07:00:00 +00:00")
|
|
|
|
pm.refresh_pairlist()
|
|
|
|
assert pm.whitelist == ['ETH/USDT', 'LTC/USDT', 'XRP/USDT',
|
|
|
|
'NEO/USDT', 'TKN/USDT', 'ADA/USDT', 'ETC/USDT']
|
2021-09-19 23:44:12 +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
|
|
|
|
2023-03-01 19:14:15 +00:00
|
|
|
mocker.patch.multiple(EXMS,
|
2019-11-09 12:40:36 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
2022-03-17 19:21:10 +00:00
|
|
|
def test_pair_whitelist_not_supported_Spread(mocker, default_conf, tickers) -> None:
|
|
|
|
default_conf['pairlists'] = [{'method': 'StaticPairList'}, {'method': 'SpreadFilter'}]
|
|
|
|
|
2023-03-01 19:14:15 +00:00
|
|
|
mocker.patch.multiple(EXMS,
|
2022-03-17 19:21:10 +00:00
|
|
|
get_tickers=tickers,
|
|
|
|
exchange_has=MagicMock(return_value=False),
|
|
|
|
)
|
|
|
|
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r'Exchange does not support fetchTickers, .*'):
|
|
|
|
get_patched_freqtradebot(mocker, default_conf)
|
|
|
|
|
2023-03-09 18:42:43 +00:00
|
|
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
|
|
|
mocker.patch(f'{EXMS}.get_option', MagicMock(return_value=False))
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r'.*requires exchange to have bid/ask data'):
|
|
|
|
get_patched_freqtradebot(mocker, default_conf)
|
|
|
|
|
2022-03-18 05:38:54 +00:00
|
|
|
|
2022-12-15 18:36:21 +00:00
|
|
|
@pytest.mark.parametrize("pairlist", TESTABLE_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
|
2023-03-01 19:14:15 +00:00
|
|
|
mocker.patch.multiple(EXMS,
|
2019-11-09 08:42:34 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2022-12-15 18:36:21 +00:00
|
|
|
@pytest.mark.parametrize("pairlist", TESTABLE_PAIRLISTS)
|
2019-03-17 17:18:44 +00:00
|
|
|
@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
|
2020-06-02 18:41:29 +00:00
|
|
|
(['ETH/BTC', 'TKN/BTC', 'BTT/BTC'], "Market is not active"),
|
|
|
|
# XLTCUSDT is not a valid pair
|
|
|
|
(['ETH/BTC', 'TKN/BTC', 'XLTCUSDT'], "is not tradable with Freqtrade"),
|
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
|
2023-03-01 19:14:15 +00:00
|
|
|
mocker.patch.multiple(EXMS,
|
2019-11-09 12:40:36 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
2022-12-15 18:36:21 +00:00
|
|
|
@pytest.mark.parametrize("pairlist", TESTABLE_PAIRLISTS)
|
2020-11-28 04:18:49 +00:00
|
|
|
def test__whitelist_for_active_markets_empty(mocker, whitelist_conf, pairlist, tickers):
|
2020-06-10 17:57:47 +00:00
|
|
|
whitelist_conf['pairlists'][0]['method'] = pairlist
|
|
|
|
|
2023-02-25 19:26:04 +00:00
|
|
|
mocker.patch(f'{EXMS}.exchange_has', return_value=True)
|
2020-06-10 17:57:47 +00:00
|
|
|
|
|
|
|
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf)
|
2023-03-01 19:14:15 +00:00
|
|
|
mocker.patch.multiple(EXMS,
|
2020-06-10 17:57:47 +00:00
|
|
|
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'])
|
|
|
|
|
|
|
|
|
2020-11-28 04:18:49 +00:00
|
|
|
def test_volumepairlist_invalid_sortvalue(mocker, 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
|
|
|
|
2023-02-25 19:26:04 +00:00
|
|
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
2019-11-09 13:44:39 +00:00
|
|
|
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):
|
|
|
|
|
2023-03-01 19:14:15 +00:00
|
|
|
mocker.patch.multiple(EXMS,
|
2019-11-09 13:44:39 +00:00
|
|
|
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)
|
2021-04-25 18:10:47 +00:00
|
|
|
assert len(freqtrade.pairlists._pairlist_handlers[0]._pair_cache) == 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
|
|
|
|
2021-04-25 18:10:47 +00:00
|
|
|
assert len(freqtrade.pairlists._pairlist_handlers[0]._pair_cache) == 1
|
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:49:25 +00:00
|
|
|
|
|
|
|
|
2020-11-28 06:24:48 +00:00
|
|
|
def test_agefilter_min_days_listed_too_small(mocker, default_conf, markets, tickers):
|
2020-07-08 17:06:30 +00:00
|
|
|
default_conf['pairlists'] = [{'method': 'VolumePairList', 'number_assets': 10},
|
|
|
|
{'method': 'AgeFilter', 'min_days_listed': -1}]
|
|
|
|
|
2023-03-01 19:14:15 +00:00
|
|
|
mocker.patch.multiple(EXMS,
|
2020-07-08 17:06:30 +00:00
|
|
|
markets=PropertyMock(return_value=markets),
|
|
|
|
exchange_has=MagicMock(return_value=True),
|
|
|
|
get_tickers=tickers
|
|
|
|
)
|
|
|
|
|
2020-07-15 11:40:54 +00:00
|
|
|
with pytest.raises(OperationalException,
|
2020-08-15 07:11:46 +00:00
|
|
|
match=r'AgeFilter requires min_days_listed to be >= 1'):
|
2020-07-15 11:40:54 +00:00
|
|
|
get_patched_freqtradebot(mocker, default_conf)
|
2020-07-08 17:06:30 +00:00
|
|
|
|
|
|
|
|
2021-07-03 16:58:04 +00:00
|
|
|
def test_agefilter_max_days_lower_than_min_days(mocker, default_conf, markets, tickers):
|
|
|
|
default_conf['pairlists'] = [{'method': 'VolumePairList', 'number_assets': 10},
|
|
|
|
{'method': 'AgeFilter', 'min_days_listed': 3,
|
|
|
|
"max_days_listed": 2}]
|
|
|
|
|
2023-03-01 19:14:15 +00:00
|
|
|
mocker.patch.multiple(EXMS,
|
2021-07-03 16:58:04 +00:00
|
|
|
markets=PropertyMock(return_value=markets),
|
|
|
|
exchange_has=MagicMock(return_value=True),
|
|
|
|
get_tickers=tickers
|
|
|
|
)
|
|
|
|
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r'AgeFilter max_days_listed <= min_days_listed not permitted'):
|
|
|
|
get_patched_freqtradebot(mocker, default_conf)
|
|
|
|
|
|
|
|
|
2020-11-28 06:24:48 +00:00
|
|
|
def test_agefilter_min_days_listed_too_large(mocker, default_conf, markets, tickers):
|
2020-07-08 17:06:30 +00:00
|
|
|
default_conf['pairlists'] = [{'method': 'VolumePairList', 'number_assets': 10},
|
|
|
|
{'method': 'AgeFilter', 'min_days_listed': 99999}]
|
|
|
|
|
2023-03-01 19:14:15 +00:00
|
|
|
mocker.patch.multiple(EXMS,
|
2020-07-08 17:06:30 +00:00
|
|
|
markets=PropertyMock(return_value=markets),
|
|
|
|
exchange_has=MagicMock(return_value=True),
|
|
|
|
get_tickers=tickers
|
|
|
|
)
|
|
|
|
|
2020-07-15 11:40:54 +00:00
|
|
|
with pytest.raises(OperationalException,
|
2020-08-15 07:11:46 +00:00
|
|
|
match=r'AgeFilter requires min_days_listed to not exceed '
|
2020-07-15 11:40:54 +00:00
|
|
|
r'exchange max request size \([0-9]+\)'):
|
|
|
|
get_patched_freqtradebot(mocker, default_conf)
|
2020-07-08 17:06:30 +00:00
|
|
|
|
|
|
|
|
2020-12-15 19:49:46 +00:00
|
|
|
def test_agefilter_caching(mocker, markets, whitelist_conf_agefilter, tickers, ohlcv_history):
|
2021-09-14 04:45:26 +00:00
|
|
|
with time_machine.travel("2021-09-01 05:00:00 +00:00") as t:
|
|
|
|
ohlcv_data = {
|
2021-12-08 13:35:15 +00:00
|
|
|
('ETH/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
|
|
|
('TKN/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
|
|
|
('LTC/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
2021-09-14 04:45:26 +00:00
|
|
|
}
|
|
|
|
mocker.patch.multiple(
|
2023-03-01 19:14:15 +00:00
|
|
|
EXMS,
|
2021-09-14 04:45:26 +00:00
|
|
|
markets=PropertyMock(return_value=markets),
|
|
|
|
exchange_has=MagicMock(return_value=True),
|
|
|
|
get_tickers=tickers,
|
|
|
|
refresh_latest_ohlcv=MagicMock(return_value=ohlcv_data),
|
|
|
|
)
|
2020-06-24 22:58:12 +00:00
|
|
|
|
2021-09-14 04:45:26 +00:00
|
|
|
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf_agefilter)
|
|
|
|
assert freqtrade.exchange.refresh_latest_ohlcv.call_count == 0
|
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
|
|
|
assert len(freqtrade.pairlists.whitelist) == 3
|
|
|
|
assert freqtrade.exchange.refresh_latest_ohlcv.call_count > 0
|
2020-06-24 22:58:12 +00:00
|
|
|
|
2021-09-14 04:45:26 +00:00
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
|
|
|
assert len(freqtrade.pairlists.whitelist) == 3
|
|
|
|
# Call to XRP/BTC cached
|
2021-09-14 05:07:20 +00:00
|
|
|
assert freqtrade.exchange.refresh_latest_ohlcv.call_count == 2
|
|
|
|
|
|
|
|
ohlcv_data = {
|
2021-12-08 13:35:15 +00:00
|
|
|
('ETH/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
|
|
|
('TKN/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
|
|
|
('LTC/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
|
|
|
('XRP/BTC', '1d', CandleType.SPOT): ohlcv_history.iloc[[0]],
|
2021-09-14 05:07:20 +00:00
|
|
|
}
|
2023-02-25 19:26:04 +00:00
|
|
|
mocker.patch(f'{EXMS}.refresh_latest_ohlcv', return_value=ohlcv_data)
|
2021-09-14 05:07:20 +00:00
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
|
|
|
assert len(freqtrade.pairlists.whitelist) == 3
|
|
|
|
assert freqtrade.exchange.refresh_latest_ohlcv.call_count == 1
|
|
|
|
|
2021-09-14 04:45:26 +00:00
|
|
|
# Move to next day
|
|
|
|
t.move_to("2021-09-02 01:00:00 +00:00")
|
2023-02-25 19:26:04 +00:00
|
|
|
mocker.patch(f'{EXMS}.refresh_latest_ohlcv', return_value=ohlcv_data)
|
2021-09-14 04:45:26 +00:00
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
|
|
|
assert len(freqtrade.pairlists.whitelist) == 3
|
2021-09-14 05:07:20 +00:00
|
|
|
assert freqtrade.exchange.refresh_latest_ohlcv.call_count == 1
|
2021-09-14 04:45:26 +00:00
|
|
|
|
|
|
|
# Move another day with fresh mocks (now the pair is old enough)
|
|
|
|
t.move_to("2021-09-03 01:00:00 +00:00")
|
|
|
|
# Called once for XRP/BTC
|
|
|
|
ohlcv_data = {
|
2021-12-08 13:35:15 +00:00
|
|
|
('ETH/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
|
|
|
('TKN/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
|
|
|
('LTC/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
|
|
|
('XRP/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
2021-09-14 04:45:26 +00:00
|
|
|
}
|
2023-02-25 19:26:04 +00:00
|
|
|
mocker.patch(f'{EXMS}.refresh_latest_ohlcv', return_value=ohlcv_data)
|
2021-09-14 04:45:26 +00:00
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
|
|
|
assert len(freqtrade.pairlists.whitelist) == 4
|
|
|
|
# Called once (only for XRP/BTC)
|
|
|
|
assert freqtrade.exchange.refresh_latest_ohlcv.call_count == 1
|
2020-06-24 22:58:12 +00:00
|
|
|
|
|
|
|
|
2021-07-07 10:06:55 +00:00
|
|
|
def test_OffsetFilter_error(mocker, whitelist_conf) -> None:
|
|
|
|
whitelist_conf['pairlists'] = (
|
|
|
|
[{"method": "StaticPairList"}, {"method": "OffsetFilter", "offset": -1}]
|
|
|
|
)
|
|
|
|
|
2023-02-25 19:26:04 +00:00
|
|
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
2021-07-07 10:06:55 +00:00
|
|
|
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r'OffsetFilter requires offset to be >= 0'):
|
|
|
|
PairListManager(MagicMock, whitelist_conf)
|
|
|
|
|
|
|
|
|
2020-11-22 18:47:27 +00:00
|
|
|
def test_rangestabilityfilter_checks(mocker, default_conf, markets, tickers):
|
2020-11-21 14:51:39 +00:00
|
|
|
default_conf['pairlists'] = [{'method': 'VolumePairList', 'number_assets': 10},
|
2020-11-22 18:47:27 +00:00
|
|
|
{'method': 'RangeStabilityFilter', 'lookback_days': 99999}]
|
2020-11-21 14:51:39 +00:00
|
|
|
|
2023-03-01 19:14:15 +00:00
|
|
|
mocker.patch.multiple(EXMS,
|
2020-11-21 14:51:39 +00:00
|
|
|
markets=PropertyMock(return_value=markets),
|
|
|
|
exchange_has=MagicMock(return_value=True),
|
|
|
|
get_tickers=tickers
|
|
|
|
)
|
|
|
|
|
|
|
|
with pytest.raises(OperationalException,
|
2020-11-22 18:47:27 +00:00
|
|
|
match=r'RangeStabilityFilter requires lookback_days to not exceed '
|
2020-11-21 14:51:39 +00:00
|
|
|
r'exchange max request size \([0-9]+\)'):
|
|
|
|
get_patched_freqtradebot(mocker, default_conf)
|
|
|
|
|
|
|
|
default_conf['pairlists'] = [{'method': 'VolumePairList', 'number_assets': 10},
|
2020-11-22 18:47:27 +00:00
|
|
|
{'method': 'RangeStabilityFilter', 'lookback_days': 0}]
|
2020-11-21 14:51:39 +00:00
|
|
|
|
|
|
|
with pytest.raises(OperationalException,
|
2020-11-22 18:47:27 +00:00
|
|
|
match='RangeStabilityFilter requires lookback_days to be >= 1'):
|
2020-11-21 14:51:39 +00:00
|
|
|
get_patched_freqtradebot(mocker, default_conf)
|
|
|
|
|
|
|
|
|
2021-07-25 07:24:55 +00:00
|
|
|
@pytest.mark.parametrize('min_rate_of_change,max_rate_of_change,expected_length', [
|
|
|
|
(0.01, 0.99, 5),
|
|
|
|
(0.05, 0.0, 0), # Setting min rate_of_change to 5% removes all pairs from the whitelist.
|
2020-11-21 15:01:52 +00:00
|
|
|
])
|
2020-12-15 19:49:46 +00:00
|
|
|
def test_rangestabilityfilter_caching(mocker, markets, default_conf, tickers, ohlcv_history,
|
2021-07-25 07:24:55 +00:00
|
|
|
min_rate_of_change, max_rate_of_change, expected_length):
|
2020-11-21 15:01:52 +00:00
|
|
|
default_conf['pairlists'] = [{'method': 'VolumePairList', 'number_assets': 10},
|
2020-11-22 18:47:27 +00:00
|
|
|
{'method': 'RangeStabilityFilter', 'lookback_days': 2,
|
2021-07-25 07:24:55 +00:00
|
|
|
'min_rate_of_change': min_rate_of_change,
|
|
|
|
"max_rate_of_change": max_rate_of_change}]
|
2020-11-21 15:01:52 +00:00
|
|
|
|
2023-03-01 19:14:15 +00:00
|
|
|
mocker.patch.multiple(EXMS,
|
2020-11-21 15:01:52 +00:00
|
|
|
markets=PropertyMock(return_value=markets),
|
|
|
|
exchange_has=MagicMock(return_value=True),
|
|
|
|
get_tickers=tickers
|
|
|
|
)
|
2020-12-15 19:49:46 +00:00
|
|
|
ohlcv_data = {
|
2021-12-08 13:35:15 +00:00
|
|
|
('ETH/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
|
|
|
('TKN/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
|
|
|
('LTC/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
|
|
|
('XRP/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
|
|
|
('HOT/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
|
|
|
('BLK/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
2020-12-15 19:49:46 +00:00
|
|
|
}
|
2020-11-21 15:01:52 +00:00
|
|
|
mocker.patch.multiple(
|
2023-03-01 19:14:15 +00:00
|
|
|
EXMS,
|
2020-12-15 19:49:46 +00:00
|
|
|
refresh_latest_ohlcv=MagicMock(return_value=ohlcv_data),
|
2020-11-21 15:01:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
2020-12-15 19:49:46 +00:00
|
|
|
assert freqtrade.exchange.refresh_latest_ohlcv.call_count == 0
|
2020-11-21 15:01:52 +00:00
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
|
|
|
assert len(freqtrade.pairlists.whitelist) == expected_length
|
2020-12-15 19:49:46 +00:00
|
|
|
assert freqtrade.exchange.refresh_latest_ohlcv.call_count > 0
|
2020-11-21 15:01:52 +00:00
|
|
|
|
2020-12-15 19:49:46 +00:00
|
|
|
previous_call_count = freqtrade.exchange.refresh_latest_ohlcv.call_count
|
2020-11-21 15:01:52 +00:00
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
|
|
|
assert len(freqtrade.pairlists.whitelist) == expected_length
|
|
|
|
# Should not have increased since first call.
|
2020-12-15 19:49:46 +00:00
|
|
|
assert freqtrade.exchange.refresh_latest_ohlcv.call_count == previous_call_count
|
2020-11-21 15:01:52 +00:00
|
|
|
|
|
|
|
|
2021-01-26 16:15:47 +00:00
|
|
|
def test_spreadfilter_invalid_data(mocker, default_conf, markets, tickers, caplog):
|
|
|
|
default_conf['pairlists'] = [{'method': 'VolumePairList', 'number_assets': 10},
|
|
|
|
{'method': 'SpreadFilter', 'max_spread_ratio': 0.1}]
|
|
|
|
|
2023-03-01 19:14:15 +00:00
|
|
|
mocker.patch.multiple(EXMS,
|
2021-01-26 16:15:47 +00:00
|
|
|
markets=PropertyMock(return_value=markets),
|
|
|
|
exchange_has=MagicMock(return_value=True),
|
|
|
|
get_tickers=tickers
|
|
|
|
)
|
|
|
|
|
|
|
|
ftbot = get_patched_freqtradebot(mocker, default_conf)
|
|
|
|
ftbot.pairlists.refresh_pairlist()
|
|
|
|
|
|
|
|
assert len(ftbot.pairlists.whitelist) == 5
|
|
|
|
|
|
|
|
tickers.return_value['ETH/BTC']['ask'] = 0.0
|
|
|
|
del tickers.return_value['TKN/BTC']
|
|
|
|
del tickers.return_value['LTC/BTC']
|
2023-03-01 19:14:15 +00:00
|
|
|
mocker.patch.multiple(EXMS, get_tickers=tickers)
|
2021-01-26 16:15:47 +00:00
|
|
|
|
|
|
|
ftbot.pairlists.refresh_pairlist()
|
|
|
|
assert log_has_re(r'Removed .* invalid ticker data.*', caplog)
|
|
|
|
|
|
|
|
assert len(ftbot.pairlists.whitelist) == 2
|
|
|
|
|
|
|
|
|
2020-07-22 19:46:30 +00:00
|
|
|
@pytest.mark.parametrize("pairlistconfig,desc_expected,exception_expected", [
|
2020-07-10 18:21:33 +00:00
|
|
|
({"method": "PriceFilter", "low_price_ratio": 0.001, "min_price": 0.00000010,
|
2020-07-22 19:46:30 +00:00
|
|
|
"max_price": 1.0},
|
|
|
|
"[{'PriceFilter': 'PriceFilter - Filtering pairs priced below "
|
|
|
|
"0.1% or below 0.00000010 or above 1.00000000.'}]",
|
|
|
|
None
|
2020-07-22 19:56:24 +00:00
|
|
|
),
|
2020-07-10 18:21:33 +00:00
|
|
|
({"method": "PriceFilter", "low_price_ratio": 0.001, "min_price": 0.00000010},
|
2020-07-22 19:46:30 +00:00
|
|
|
"[{'PriceFilter': 'PriceFilter - Filtering pairs priced below 0.1% or below 0.00000010.'}]",
|
|
|
|
None
|
2020-07-22 19:56:24 +00:00
|
|
|
),
|
2020-07-10 18:21:33 +00:00
|
|
|
({"method": "PriceFilter", "low_price_ratio": 0.001, "max_price": 1.00010000},
|
2020-07-22 19:46:30 +00:00
|
|
|
"[{'PriceFilter': 'PriceFilter - Filtering pairs priced below 0.1% or above 1.00010000.'}]",
|
|
|
|
None
|
2020-07-22 19:56:24 +00:00
|
|
|
),
|
2020-07-10 18:21:33 +00:00
|
|
|
({"method": "PriceFilter", "min_price": 0.00002000},
|
2020-07-22 19:46:30 +00:00
|
|
|
"[{'PriceFilter': 'PriceFilter - Filtering pairs priced below 0.00002000.'}]",
|
|
|
|
None
|
2020-07-22 19:56:24 +00:00
|
|
|
),
|
2021-05-17 04:47:49 +00:00
|
|
|
({"method": "PriceFilter", "max_value": 0.00002000},
|
|
|
|
"[{'PriceFilter': 'PriceFilter - Filtering pairs priced Value above 0.00002000.'}]",
|
|
|
|
None
|
|
|
|
),
|
2020-07-10 18:21:33 +00:00
|
|
|
({"method": "PriceFilter"},
|
2020-07-22 19:46:30 +00:00
|
|
|
"[{'PriceFilter': 'PriceFilter - No price filters configured.'}]",
|
|
|
|
None
|
2020-07-22 19:56:24 +00:00
|
|
|
),
|
2020-07-22 19:46:30 +00:00
|
|
|
({"method": "PriceFilter", "low_price_ratio": -0.001},
|
|
|
|
None,
|
2020-08-15 07:11:46 +00:00
|
|
|
"PriceFilter requires low_price_ratio to be >= 0"
|
2020-07-22 19:56:24 +00:00
|
|
|
), # OperationalException expected
|
2020-07-22 19:46:30 +00:00
|
|
|
({"method": "PriceFilter", "min_price": -0.00000010},
|
|
|
|
None,
|
2020-08-15 07:11:46 +00:00
|
|
|
"PriceFilter requires min_price to be >= 0"
|
2020-07-22 19:56:24 +00:00
|
|
|
), # OperationalException expected
|
2020-07-22 19:46:30 +00:00
|
|
|
({"method": "PriceFilter", "max_price": -1.00010000},
|
|
|
|
None,
|
2020-08-15 07:11:46 +00:00
|
|
|
"PriceFilter requires max_price to be >= 0"
|
2020-07-22 19:56:24 +00:00
|
|
|
), # OperationalException expected
|
2021-05-17 04:47:49 +00:00
|
|
|
({"method": "PriceFilter", "max_value": -1.00010000},
|
|
|
|
None,
|
|
|
|
"PriceFilter requires max_value to be >= 0"
|
|
|
|
), # OperationalException expected
|
2021-08-02 05:15:09 +00:00
|
|
|
({"method": "RangeStabilityFilter", "lookback_days": 10,
|
|
|
|
"min_rate_of_change": 0.01},
|
|
|
|
"[{'RangeStabilityFilter': 'RangeStabilityFilter - Filtering pairs with rate of change below "
|
|
|
|
"0.01 over the last days.'}]",
|
|
|
|
None
|
|
|
|
),
|
2021-07-25 07:24:55 +00:00
|
|
|
({"method": "RangeStabilityFilter", "lookback_days": 10,
|
|
|
|
"min_rate_of_change": 0.01, "max_rate_of_change": 0.99},
|
2020-11-22 18:47:27 +00:00
|
|
|
"[{'RangeStabilityFilter': 'RangeStabilityFilter - Filtering pairs with rate of change below "
|
2021-07-25 07:24:55 +00:00
|
|
|
"0.01 and above 0.99 over the last days.'}]",
|
2020-11-21 14:39:04 +00:00
|
|
|
None
|
|
|
|
),
|
2022-05-14 12:14:53 +00:00
|
|
|
({"method": "OffsetFilter", "offset": 5, "number_assets": 10},
|
|
|
|
"[{'OffsetFilter': 'OffsetFilter - Taking 10 Pairs, starting from 5.'}]",
|
|
|
|
None
|
|
|
|
),
|
2022-09-25 08:13:00 +00:00
|
|
|
({"method": "ProducerPairList"},
|
|
|
|
"[{'ProducerPairList': 'ProducerPairList - default'}]",
|
|
|
|
None
|
|
|
|
),
|
2023-07-09 09:36:13 +00:00
|
|
|
({"method": "RemotePairList", "number_assets": 10, "pairlist_url": "https://example.com"},
|
|
|
|
"[{'RemotePairList': 'RemotePairList - 10 pairs from RemotePairlist.'}]",
|
|
|
|
None
|
|
|
|
),
|
2020-07-10 18:21:33 +00:00
|
|
|
])
|
2020-07-22 19:46:30 +00:00
|
|
|
def test_pricefilter_desc(mocker, whitelist_conf, markets, pairlistconfig,
|
|
|
|
desc_expected, exception_expected):
|
2023-03-01 19:14:15 +00:00
|
|
|
mocker.patch.multiple(EXMS,
|
2020-07-10 18:21:33 +00:00
|
|
|
markets=PropertyMock(return_value=markets),
|
|
|
|
exchange_has=MagicMock(return_value=True)
|
|
|
|
)
|
|
|
|
whitelist_conf['pairlists'] = [pairlistconfig]
|
|
|
|
|
2020-07-22 19:46:30 +00:00
|
|
|
if desc_expected is not None:
|
|
|
|
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf)
|
|
|
|
short_desc = str(freqtrade.pairlists.short_desc())
|
|
|
|
assert short_desc == desc_expected
|
2020-07-22 19:56:24 +00:00
|
|
|
else: # OperationalException expected
|
2020-07-22 19:46:30 +00:00
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=exception_expected):
|
|
|
|
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf)
|
2020-07-10 18:21:33 +00:00
|
|
|
|
|
|
|
|
2020-11-28 04:18:49 +00:00
|
|
|
def test_pairlistmanager_no_pairlist(mocker, whitelist_conf):
|
2023-02-25 19:26:04 +00:00
|
|
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
2019-11-09 13:49:25 +00:00
|
|
|
|
|
|
|
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)
|
2020-11-28 06:24:48 +00:00
|
|
|
|
|
|
|
|
2020-11-28 07:15:36 +00:00
|
|
|
@pytest.mark.parametrize("pairlists,pair_allowlist,overall_performance,allowlist_result", [
|
2020-11-28 15:45:17 +00:00
|
|
|
# No trades yet
|
|
|
|
([{"method": "StaticPairList"}, {"method": "PerformanceFilter"}],
|
|
|
|
['ETH/BTC', 'TKN/BTC', 'LTC/BTC'], [], ['ETH/BTC', 'TKN/BTC', 'LTC/BTC']),
|
|
|
|
# Happy path: Descending order, all values filled
|
2020-11-28 07:34:18 +00:00
|
|
|
([{"method": "StaticPairList"}, {"method": "PerformanceFilter"}],
|
|
|
|
['ETH/BTC', 'TKN/BTC'],
|
2021-12-12 12:21:24 +00:00
|
|
|
[{'pair': 'TKN/BTC', 'profit_ratio': 0.05, 'count': 3},
|
|
|
|
{'pair': 'ETH/BTC', 'profit_ratio': 0.04, 'count': 2}],
|
2020-11-28 07:34:18 +00:00
|
|
|
['TKN/BTC', 'ETH/BTC']),
|
2020-11-28 07:15:36 +00:00
|
|
|
# Performance data outside allow list ignored
|
2020-11-28 07:34:18 +00:00
|
|
|
([{"method": "StaticPairList"}, {"method": "PerformanceFilter"}],
|
|
|
|
['ETH/BTC', 'TKN/BTC'],
|
2021-12-12 12:21:24 +00:00
|
|
|
[{'pair': 'OTHER/BTC', 'profit_ratio': 0.05, 'count': 3},
|
|
|
|
{'pair': 'ETH/BTC', 'profit_ratio': 0.04, 'count': 2}],
|
2020-11-28 07:34:18 +00:00
|
|
|
['ETH/BTC', 'TKN/BTC']),
|
2020-11-28 07:15:36 +00:00
|
|
|
# Partial performance data missing and sorted between positive and negative profit
|
2020-11-28 07:34:18 +00:00
|
|
|
([{"method": "StaticPairList"}, {"method": "PerformanceFilter"}],
|
|
|
|
['ETH/BTC', 'TKN/BTC', 'LTC/BTC'],
|
2021-12-12 12:21:24 +00:00
|
|
|
[{'pair': 'ETH/BTC', 'profit_ratio': -0.05, 'count': 100},
|
|
|
|
{'pair': 'TKN/BTC', 'profit_ratio': 0.04, 'count': 2}],
|
2020-11-28 07:34:18 +00:00
|
|
|
['TKN/BTC', 'LTC/BTC', 'ETH/BTC']),
|
2020-11-28 18:17:03 +00:00
|
|
|
# Tie in performance data broken by count (ascending)
|
2020-11-28 07:34:18 +00:00
|
|
|
([{"method": "StaticPairList"}, {"method": "PerformanceFilter"}],
|
|
|
|
['ETH/BTC', 'TKN/BTC', 'LTC/BTC'],
|
2021-12-12 12:21:24 +00:00
|
|
|
[{'pair': 'LTC/BTC', 'profit_ratio': -0.0501, 'count': 101},
|
|
|
|
{'pair': 'TKN/BTC', 'profit_ratio': -0.0501, 'count': 2},
|
|
|
|
{'pair': 'ETH/BTC', 'profit_ratio': -0.0501, 'count': 100}],
|
2020-11-28 18:17:03 +00:00
|
|
|
['TKN/BTC', 'ETH/BTC', 'LTC/BTC']),
|
2022-02-06 15:19:11 +00:00
|
|
|
# Tie in performance and count, broken by prior sorting sort
|
2020-11-28 18:17:03 +00:00
|
|
|
([{"method": "StaticPairList"}, {"method": "PerformanceFilter"}],
|
|
|
|
['ETH/BTC', 'TKN/BTC', 'LTC/BTC'],
|
2021-12-12 12:21:24 +00:00
|
|
|
[{'pair': 'LTC/BTC', 'profit_ratio': -0.0501, 'count': 1},
|
|
|
|
{'pair': 'TKN/BTC', 'profit_ratio': -0.0501, 'count': 1},
|
|
|
|
{'pair': 'ETH/BTC', 'profit_ratio': -0.0501, 'count': 1}],
|
2022-02-06 15:19:11 +00:00
|
|
|
['ETH/BTC', 'TKN/BTC', 'LTC/BTC']),
|
2020-11-28 07:15:36 +00:00
|
|
|
])
|
2020-11-28 07:34:18 +00:00
|
|
|
def test_performance_filter(mocker, whitelist_conf, pairlists, pair_allowlist, overall_performance,
|
|
|
|
allowlist_result, tickers, markets, ohlcv_history_list):
|
2020-11-28 07:15:36 +00:00
|
|
|
allowlist_conf = whitelist_conf
|
|
|
|
allowlist_conf['pairlists'] = pairlists
|
|
|
|
allowlist_conf['exchange']['pair_whitelist'] = pair_allowlist
|
|
|
|
|
2023-02-25 19:26:04 +00:00
|
|
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
2020-11-28 07:15:36 +00:00
|
|
|
|
|
|
|
freqtrade = get_patched_freqtradebot(mocker, allowlist_conf)
|
2023-03-01 19:14:15 +00:00
|
|
|
mocker.patch.multiple(EXMS,
|
2020-11-28 07:15:36 +00:00
|
|
|
get_tickers=tickers,
|
|
|
|
markets=PropertyMock(return_value=markets)
|
|
|
|
)
|
2023-03-01 19:14:15 +00:00
|
|
|
mocker.patch.multiple(EXMS,
|
2020-11-28 07:34:18 +00:00
|
|
|
get_historic_ohlcv=MagicMock(return_value=ohlcv_history_list),
|
2020-11-28 07:43:19 +00:00
|
|
|
)
|
2020-11-28 07:15:36 +00:00
|
|
|
mocker.patch.multiple('freqtrade.persistence.Trade',
|
2020-11-28 07:34:18 +00:00
|
|
|
get_overall_performance=MagicMock(return_value=overall_performance),
|
|
|
|
)
|
2020-11-28 07:15:36 +00:00
|
|
|
freqtrade.pairlists.refresh_pairlist()
|
|
|
|
allowlist = freqtrade.pairlists.whitelist
|
|
|
|
assert allowlist == allowlist_result
|
2020-12-30 08:55:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
@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),
|
2021-01-23 19:35:10 +00:00
|
|
|
(['BTC/USD'],
|
|
|
|
['BTC/USD', 'BTC/USDT'],
|
|
|
|
['BTC/USD']),
|
2020-12-30 08:55:44 +00:00
|
|
|
])
|
|
|
|
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)
|
2022-08-13 08:18:57 +00:00
|
|
|
conf = {
|
|
|
|
'pairs': wildcardlist,
|
|
|
|
'freqai': {
|
|
|
|
"enabled": True,
|
|
|
|
"feature_parameters": {
|
|
|
|
"include_corr_pairlist": [
|
|
|
|
"BTC/USDT:USDT",
|
|
|
|
"XRP/BUSD",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert sorted(dynamic_expand_pairlist(conf, pairs)) == sorted(expected + [
|
|
|
|
"BTC/USDT:USDT",
|
|
|
|
"XRP/BUSD",
|
|
|
|
])
|
2021-01-14 23:13:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
@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', 'ETH/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),
|
2021-01-23 19:35:10 +00:00
|
|
|
(['HELLO/WORLD'], [], ['HELLO/WORLD']), # Invalid pair kept
|
|
|
|
(['BTC/USD'],
|
|
|
|
['BTC/USD', 'BTC/USDT'],
|
|
|
|
['BTC/USD']),
|
2023-08-29 15:40:18 +00:00
|
|
|
(['BTC/USDT:USDT'],
|
|
|
|
['BTC/USDT:USDT', 'BTC/USDT'],
|
|
|
|
['BTC/USDT:USDT']),
|
2023-08-29 15:44:39 +00:00
|
|
|
(['BB_BTC/USDT', 'CC_BTC/USDT', 'AA_ETH/USDT', 'XRP/USDT', 'ETH/USDT', 'XX_BTC/USDT'],
|
|
|
|
['BTC/USDT', 'ETH/USDT'],
|
|
|
|
['XRP/USDT', 'ETH/USDT']),
|
2021-01-14 23:13:11 +00:00
|
|
|
])
|
|
|
|
def test_expand_pairlist_keep_invalid(wildcardlist, pairs, expected):
|
|
|
|
if expected is None:
|
|
|
|
with pytest.raises(ValueError, match=r'Wildcard error in \*UP/USDT,'):
|
|
|
|
expand_pairlist(wildcardlist, pairs, keep_invalid=True)
|
|
|
|
else:
|
|
|
|
assert sorted(expand_pairlist(wildcardlist, pairs, keep_invalid=True)) == sorted(expected)
|
2022-09-25 08:13:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_ProducerPairlist_no_emc(mocker, whitelist_conf):
|
2023-02-25 19:26:04 +00:00
|
|
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
2022-09-25 08:13:00 +00:00
|
|
|
|
|
|
|
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):
|
2023-02-25 19:26:04 +00:00
|
|
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
2023-03-01 19:14:15 +00:00
|
|
|
mocker.patch.multiple(EXMS,
|
2022-09-25 08:13:00 +00:00
|
|
|
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
|
2022-09-25 17:32:39 +00:00
|
|
|
whitelist_conf['exchange']['pair_whitelist'] = ['TKN/BTC']
|
|
|
|
|
|
|
|
whitelist_conf['pairlists'] = [
|
|
|
|
{"method": "StaticPairList"},
|
|
|
|
{
|
|
|
|
"method": "ProducerPairList",
|
|
|
|
"producer_name": "hello_world",
|
|
|
|
}
|
|
|
|
]
|
|
|
|
pm = PairListManager(exchange, whitelist_conf, dp)
|
|
|
|
pm.refresh_pairlist()
|
|
|
|
assert len(pm.whitelist) == 4
|
|
|
|
assert pm.whitelist == ['TKN/BTC'] + pairs
|
2023-09-22 00:43:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures("init_persistence")
|
|
|
|
def test_FullTradesFilter(mocker, default_conf_usdt, fee, caplog) -> None:
|
|
|
|
default_conf_usdt['exchange']['pair_whitelist'].extend(['ADA/USDT', 'XRP/USDT', 'ETC/USDT'])
|
|
|
|
default_conf_usdt['pairlists'] = [
|
|
|
|
{"method": "StaticPairList"},
|
|
|
|
{"method": "FullTradesFilter"}
|
|
|
|
]
|
|
|
|
default_conf_usdt['max_open_trades'] = -1
|
|
|
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
|
|
|
exchange = get_patched_exchange(mocker, default_conf_usdt)
|
|
|
|
pm = PairListManager(exchange, default_conf_usdt)
|
|
|
|
pm.refresh_pairlist()
|
|
|
|
|
|
|
|
assert pm.whitelist == ['ETH/USDT', 'XRP/USDT', 'NEO/USDT', 'TKN/USDT']
|
|
|
|
|
|
|
|
with time_machine.travel("2021-09-01 05:00:00 +00:00") as t:
|
|
|
|
create_mock_trades_usdt(fee)
|
|
|
|
pm.refresh_pairlist()
|
|
|
|
|
|
|
|
# Unlimited max open trades, so no change to whitelist
|
|
|
|
pm.refresh_pairlist()
|
|
|
|
assert pm.whitelist == ['ETH/USDT', 'XRP/USDT', 'NEO/USDT', 'TKN/USDT']
|
|
|
|
|
|
|
|
# Set max_open_trades to 4, the filter should empty the whitelist
|
|
|
|
default_conf_usdt['max_open_trades'] = 4
|
|
|
|
pm.refresh_pairlist()
|
|
|
|
assert pm.whitelist == []
|
|
|
|
assert log_has_re(r'Whitelist with 0 pairs: \[]', caplog)
|
|
|
|
|
|
|
|
list_trades = LocalTrade.get_open_trades()
|
|
|
|
assert len(list_trades) == 4
|
|
|
|
|
|
|
|
# Move to 1 hour later, close a trade, so original sorting is restored.
|
|
|
|
t.move_to("2021-09-01 07:00:00 +00:00")
|
|
|
|
list_trades[2].close(12)
|
|
|
|
Trade.commit()
|
|
|
|
|
|
|
|
# open trades count below max_open_trades, whitelist restored
|
|
|
|
list_trades = LocalTrade.get_open_trades()
|
|
|
|
assert len(list_trades) == 3
|
|
|
|
pm.refresh_pairlist()
|
|
|
|
assert pm.whitelist == ['ETH/USDT', 'XRP/USDT', 'NEO/USDT', 'TKN/USDT']
|
|
|
|
|
|
|
|
# Set max_open_trades to 3, the filter should empty the whitelist
|
|
|
|
default_conf_usdt['max_open_trades'] = 3
|
|
|
|
pm.refresh_pairlist()
|
|
|
|
assert pm.whitelist == []
|
|
|
|
assert log_has_re(r'Whitelist with 0 pairs: \[]', caplog)
|
2024-01-27 09:10:10 +00:00
|
|
|
|
|
|
|
|
2024-01-29 18:46:21 +00:00
|
|
|
@pytest.mark.parametrize('pairlists,trade_mode,result', [
|
2024-01-27 13:52:05 +00:00
|
|
|
([
|
2024-01-29 08:57:14 +00:00
|
|
|
# Get 2 pairs
|
2024-01-27 13:52:05 +00:00
|
|
|
{"method": "StaticPairList", "allow_inactive": True},
|
2024-01-29 08:57:14 +00:00
|
|
|
{"method": "MarketCapPairList", "number_assets": 2}
|
2024-01-29 18:46:21 +00:00
|
|
|
], 'spot', ['BTC/USDT', 'ETH/USDT']),
|
2024-01-27 13:52:05 +00:00
|
|
|
([
|
2024-01-29 08:57:14 +00:00
|
|
|
# Get 6 pairs
|
2024-01-27 13:52:05 +00:00
|
|
|
{"method": "StaticPairList", "allow_inactive": True},
|
2024-01-29 08:57:14 +00:00
|
|
|
{"method": "MarketCapPairList", "number_assets": 6}
|
2024-01-29 18:46:21 +00:00
|
|
|
], 'spot', ['BTC/USDT', 'ETH/USDT', 'XRP/USDT', 'ADA/USDT']),
|
2024-01-27 13:52:05 +00:00
|
|
|
([
|
2024-01-29 08:57:14 +00:00
|
|
|
# Get 3 pairs within top 6 ranks
|
2024-01-27 13:52:05 +00:00
|
|
|
{"method": "StaticPairList", "allow_inactive": True},
|
2024-01-29 08:57:14 +00:00
|
|
|
{"method": "MarketCapPairList", "max_rank": 6, "number_assets": 3}
|
2024-01-29 18:46:21 +00:00
|
|
|
], 'spot', ['BTC/USDT', 'ETH/USDT', 'XRP/USDT']),
|
2024-01-27 13:52:05 +00:00
|
|
|
|
|
|
|
([
|
2024-01-29 08:57:14 +00:00
|
|
|
# Get 4 pairs within top 8 ranks
|
2024-01-27 13:52:05 +00:00
|
|
|
{"method": "StaticPairList", "allow_inactive": True},
|
2024-01-29 08:57:14 +00:00
|
|
|
{"method": "MarketCapPairList", "max_rank": 8, "number_assets": 4}
|
2024-01-29 18:46:21 +00:00
|
|
|
], 'spot', ['BTC/USDT', 'ETH/USDT', 'XRP/USDT']),
|
2024-01-27 13:52:05 +00:00
|
|
|
([
|
|
|
|
# MarketCapPairList as generator
|
2024-01-29 08:57:14 +00:00
|
|
|
{"method": "MarketCapPairList", "number_assets": 5}
|
2024-01-29 18:46:21 +00:00
|
|
|
], 'spot', ['BTC/USDT', 'ETH/USDT', 'XRP/USDT']),
|
|
|
|
([
|
|
|
|
# MarketCapPairList as generator - low max_rank
|
|
|
|
{"method": "MarketCapPairList", "max_rank": 2, "number_assets": 5}
|
|
|
|
], 'spot', ['BTC/USDT', 'ETH/USDT']),
|
|
|
|
([
|
|
|
|
# MarketCapPairList as generator - futures - low max_rank
|
|
|
|
{"method": "MarketCapPairList", "max_rank": 2, "number_assets": 5}
|
|
|
|
], 'futures', ['ETH/USDT:USDT']),
|
|
|
|
([
|
|
|
|
# MarketCapPairList as generator - futures - low number_assets
|
|
|
|
{"method": "MarketCapPairList", "number_assets": 2}
|
|
|
|
], 'futures', ['ETH/USDT:USDT', 'ADA/USDT:USDT']),
|
2024-01-27 13:52:05 +00:00
|
|
|
])
|
2024-01-29 19:10:50 +00:00
|
|
|
def test_MarketCapPairList_filter(
|
|
|
|
mocker, default_conf_usdt, trade_mode, markets, pairlists, result
|
|
|
|
):
|
2024-01-27 10:12:50 +00:00
|
|
|
test_value = [
|
2024-01-29 18:46:21 +00:00
|
|
|
{"symbol": "btc"},
|
|
|
|
{"symbol": "eth"},
|
|
|
|
{"symbol": "usdt"},
|
|
|
|
{"symbol": "bnb"},
|
|
|
|
{"symbol": "sol"},
|
|
|
|
{"symbol": "xrp"},
|
|
|
|
{"symbol": "usdc"},
|
|
|
|
{"symbol": "steth"},
|
|
|
|
{"symbol": "ada"},
|
|
|
|
{"symbol": "avax"},
|
2024-01-27 09:10:10 +00:00
|
|
|
]
|
|
|
|
|
2024-01-29 18:46:21 +00:00
|
|
|
default_conf_usdt['trading_mode'] = trade_mode
|
|
|
|
if trade_mode == 'spot':
|
|
|
|
default_conf_usdt['exchange']['pair_whitelist'].extend(['BTC/USDT', 'ETC/USDT', 'ADA/USDT'])
|
2024-01-27 13:52:05 +00:00
|
|
|
default_conf_usdt['pairlists'] = pairlists
|
2024-01-27 15:07:55 +00:00
|
|
|
mocker.patch.multiple(EXMS,
|
|
|
|
markets=PropertyMock(return_value=markets),
|
|
|
|
exchange_has=MagicMock(return_value=True),
|
|
|
|
)
|
2024-01-27 09:10:10 +00:00
|
|
|
|
2024-01-27 10:12:50 +00:00
|
|
|
mocker.patch("freqtrade.plugins.pairlist.MarketCapPairList.CoinGeckoAPI.get_coins_markets",
|
|
|
|
return_value=test_value)
|
2024-01-27 09:10:10 +00:00
|
|
|
|
|
|
|
exchange = get_patched_exchange(mocker, default_conf_usdt)
|
|
|
|
|
|
|
|
pm = PairListManager(exchange, default_conf_usdt)
|
2024-01-27 10:33:12 +00:00
|
|
|
pm.refresh_pairlist()
|
|
|
|
|
2024-01-27 13:52:05 +00:00
|
|
|
assert pm.whitelist == result
|
2024-01-29 19:01:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_MarketCapPairList_timing(mocker, default_conf_usdt, markets, time_machine):
|
|
|
|
test_value = [
|
|
|
|
{"symbol": "btc"},
|
|
|
|
{"symbol": "eth"},
|
|
|
|
{"symbol": "usdt"},
|
|
|
|
{"symbol": "bnb"},
|
|
|
|
{"symbol": "sol"},
|
|
|
|
{"symbol": "xrp"},
|
|
|
|
{"symbol": "usdc"},
|
|
|
|
{"symbol": "steth"},
|
|
|
|
{"symbol": "ada"},
|
|
|
|
{"symbol": "avax"},
|
|
|
|
]
|
|
|
|
|
|
|
|
default_conf_usdt['trading_mode'] = 'spot'
|
|
|
|
default_conf_usdt['exchange']['pair_whitelist'].extend(['BTC/USDT', 'ETC/USDT', 'ADA/USDT'])
|
|
|
|
default_conf_usdt['pairlists'] = [{"method": "MarketCapPairList", "number_assets": 2}]
|
|
|
|
|
|
|
|
markets_mock = MagicMock(return_value=markets)
|
|
|
|
mocker.patch.multiple(EXMS,
|
|
|
|
get_markets=markets_mock,
|
|
|
|
exchange_has=MagicMock(return_value=True),
|
|
|
|
)
|
|
|
|
|
|
|
|
mocker.patch("freqtrade.plugins.pairlist.MarketCapPairList.CoinGeckoAPI.get_coins_markets",
|
|
|
|
return_value=test_value)
|
|
|
|
|
|
|
|
start_dt = dt_now()
|
|
|
|
|
|
|
|
exchange = get_patched_exchange(mocker, default_conf_usdt)
|
|
|
|
time_machine.move_to(start_dt)
|
|
|
|
|
|
|
|
pm = PairListManager(exchange, default_conf_usdt)
|
|
|
|
markets_mock.reset_mock()
|
|
|
|
pm.refresh_pairlist()
|
|
|
|
assert markets_mock.call_count == 3
|
|
|
|
markets_mock.reset_mock()
|
|
|
|
|
|
|
|
time_machine.move_to(start_dt + timedelta(hours=20))
|
|
|
|
pm.refresh_pairlist()
|
|
|
|
# Cached pairlist ...
|
|
|
|
assert markets_mock.call_count == 1
|
|
|
|
|
|
|
|
markets_mock.reset_mock()
|
|
|
|
time_machine.move_to(start_dt + timedelta(days=2))
|
|
|
|
pm.refresh_pairlist()
|
|
|
|
# No longer cached pairlist ...
|
|
|
|
assert markets_mock.call_count == 3
|
2024-01-29 19:08:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_MarketCapPairList_exceptions(mocker, default_conf_usdt, markets, time_machine):
|
|
|
|
|
|
|
|
exchange = get_patched_exchange(mocker, default_conf_usdt)
|
|
|
|
default_conf_usdt['pairlists'] = [{"method": "MarketCapPairList"}]
|
|
|
|
with pytest.raises(OperationalException, match=r"`number_assets` not specified.*"):
|
|
|
|
# No number_assets
|
|
|
|
PairListManager(exchange, default_conf_usdt)
|
|
|
|
|
|
|
|
default_conf_usdt['pairlists'] = [{
|
|
|
|
"method": "MarketCapPairList", 'number_assets': 20, 'max_rank': 260
|
|
|
|
}]
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match="This filter only support marketcap rank up to 250."):
|
|
|
|
PairListManager(exchange, default_conf_usdt)
|