Performancefilter - improve sorting

Ordering of Pairs without history should remain identical, so pairs with
positive performance move to the front, and negative pairs move to the back.

closes #4893
This commit is contained in:
Matthias
2022-02-06 16:19:11 +01:00
parent ef086d438c
commit 5eb5029856
3 changed files with 33 additions and 4 deletions

View File

@@ -740,6 +740,33 @@ def test_PerformanceFilter_lookback(mocker, default_conf_usdt, fee, caplog) -> N
assert pm.whitelist == ['ETH/USDT', 'XRP/USDT', 'NEO/USDT', 'TKN/USDT']
@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, }
]
mocker.patch('freqtrade.exchange.Exchange.exchange_has', 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', '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()
assert pm.whitelist == ['XRP/USDT', 'ETC/USDT', 'ETH/USDT',
'NEO/USDT', 'TKN/USDT', 'ADA/USDT', 'LTC/USDT']
# 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']
def test_gen_pair_whitelist_not_supported(mocker, default_conf, tickers) -> None:
@@ -1170,13 +1197,13 @@ def test_pairlistmanager_no_pairlist(mocker, whitelist_conf):
{'pair': 'TKN/BTC', 'profit_ratio': -0.0501, 'count': 2},
{'pair': 'ETH/BTC', 'profit_ratio': -0.0501, 'count': 100}],
['TKN/BTC', 'ETH/BTC', 'LTC/BTC']),
# Tie in performance and count, broken by alphabetical sort
# Tie in performance and count, broken by prior sorting sort
([{"method": "StaticPairList"}, {"method": "PerformanceFilter"}],
['ETH/BTC', 'TKN/BTC', 'LTC/BTC'],
[{'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}],
['ETH/BTC', 'LTC/BTC', 'TKN/BTC']),
['ETH/BTC', 'TKN/BTC', 'LTC/BTC']),
])
def test_performance_filter(mocker, whitelist_conf, pairlists, pair_allowlist, overall_performance,
allowlist_result, tickers, markets, ohlcv_history_list):