Add test cases
This commit is contained in:
parent
26855800a3
commit
662ec32073
@ -45,10 +45,10 @@ class PerformanceFilter(IPairList):
|
|||||||
"""
|
"""
|
||||||
# Get the trading performance for pairs from database
|
# Get the trading performance for pairs from database
|
||||||
perf = pd.DataFrame(Trade.get_overall_performance())
|
perf = pd.DataFrame(Trade.get_overall_performance())
|
||||||
# update pairlist with values from performance dataframe
|
# get pairlist from performance dataframe values
|
||||||
|
list_df = pd.DataFrame({'pair':pairlist})
|
||||||
# set initial value for pairs with no trades to 0
|
# set initial value for pairs with no trades to 0
|
||||||
# and sort the list using performance and count
|
# and sort the list using performance and count
|
||||||
list_df = pd.DataFrame({'pair':pairlist})
|
|
||||||
sorted_df = list_df.join(perf.set_index('pair'), on='pair')\
|
sorted_df = list_df.join(perf.set_index('pair'), on='pair')\
|
||||||
.fillna(0).sort_values(by=['profit', 'count'], ascending=False)
|
.fillna(0).sort_values(by=['profit', 'count'], ascending=False)
|
||||||
pairlist = sorted_df['pair'].tolist()
|
pairlist = sorted_df['pair'].tolist()
|
||||||
|
@ -662,29 +662,48 @@ def test_pairlistmanager_no_pairlist(mocker, whitelist_conf):
|
|||||||
get_patched_freqtradebot(mocker, whitelist_conf)
|
get_patched_freqtradebot(mocker, whitelist_conf)
|
||||||
|
|
||||||
|
|
||||||
# @pytest.mark.parametrize("pairlists,base_currency,overall_performance,expected", [
|
@pytest.mark.parametrize("pairlists,pair_allowlist,overall_performance,allowlist_result", [
|
||||||
# # Happy path, descening order, all values filled
|
# Happy path, descending order, all values filled
|
||||||
# ([{"method": "StaticPairList"},{"method": "PerformanceFilter"}],'BTC',[{'pair':'ETH/BTC','profit':5,'count':3}, {'pair':'ETC/BTC','profit':4,'count':2}],['ETC/BTC']),
|
([{"method": "StaticPairList"},{"method": "PerformanceFilter"}],
|
||||||
# ])
|
['ETH/BTC','TKN/BTC'],
|
||||||
# def test_performance_filter(mocker, whitelist_conf, base_currency, pairlists, overall_performance, expected, tickers, markets, ohlcv_history_list):
|
[{'pair':'TKN/BTC','profit':5,'count':3}, {'pair':'ETH/BTC','profit':4,'count':2}],
|
||||||
# whitelist_conf['pairlists'] = pairlists
|
['TKN/BTC','ETH/BTC']),
|
||||||
# whitelist_conf['stake_currency'] = base_currency
|
# Performance data outside allow list ignored
|
||||||
|
([{"method": "StaticPairList"},{"method": "PerformanceFilter"}],
|
||||||
|
['ETH/BTC','TKN/BTC'],
|
||||||
|
[{'pair':'OTHER/BTC','profit':5,'count':3}, {'pair':'ETH/BTC','profit':4,'count':2}],
|
||||||
|
['ETH/BTC','TKN/BTC']),
|
||||||
|
# Partial performance data missing and sorted between positive and negative profit
|
||||||
|
([{"method": "StaticPairList"},{"method": "PerformanceFilter"}],
|
||||||
|
['ETH/BTC','TKN/BTC','LTC/BTC'],
|
||||||
|
[{'pair':'ETH/BTC','profit':-5,'count':100}, {'pair':'TKN/BTC','profit':4,'count':2}],
|
||||||
|
['TKN/BTC','LTC/BTC','ETH/BTC']),
|
||||||
|
# Tie in performance data broken by count
|
||||||
|
([{"method": "StaticPairList"},{"method": "PerformanceFilter"}],
|
||||||
|
['ETH/BTC','TKN/BTC','LTC/BTC'],
|
||||||
|
[{'pair':'LTC/BTC','profit':-5,'count':101}, {'pair':'TKN/BTC','profit':-5,'count':2}, {'pair':'ETH/BTC','profit':-5,'count':100}, ],
|
||||||
|
['LTC/BTC','ETH/BTC','TKN/BTC']),
|
||||||
|
])
|
||||||
|
def test_performance_filter(mocker, whitelist_conf, pairlists, pair_allowlist, overall_performance, allowlist_result, tickers, markets, ohlcv_history_list):
|
||||||
|
allowlist_conf = whitelist_conf
|
||||||
|
allowlist_conf['pairlists'] = pairlists
|
||||||
|
allowlist_conf['exchange']['pair_whitelist'] = pair_allowlist
|
||||||
|
|
||||||
# mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
|
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
|
||||||
|
|
||||||
# freqtrade = get_patched_freqtradebot(mocker, whitelist_conf)
|
freqtrade = get_patched_freqtradebot(mocker, allowlist_conf)
|
||||||
# mocker.patch.multiple('freqtrade.exchange.Exchange',
|
mocker.patch.multiple('freqtrade.exchange.Exchange',
|
||||||
# get_tickers=tickers,
|
get_tickers=tickers,
|
||||||
# markets=PropertyMock(return_value=markets)
|
markets=PropertyMock(return_value=markets)
|
||||||
# )
|
)
|
||||||
# mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
# 'freqtrade.exchange.Exchange',
|
'freqtrade.exchange.Exchange',
|
||||||
# get_historic_ohlcv=MagicMock(return_value=ohlcv_history_list),
|
get_historic_ohlcv=MagicMock(return_value=ohlcv_history_list),
|
||||||
# )
|
)
|
||||||
|
|
||||||
# mocker.patch.multiple('freqtrade.persistence.Trade',
|
mocker.patch.multiple('freqtrade.persistence.Trade',
|
||||||
# get_overall_performance=MagicMock(return_value=overall_performance),
|
get_overall_performance=MagicMock(return_value=overall_performance),
|
||||||
# )
|
)
|
||||||
# freqtrade.pairlists.refresh_pairlist()
|
freqtrade.pairlists.refresh_pairlist()
|
||||||
# whitelist = freqtrade.pairlists.whitelist
|
allowlist = freqtrade.pairlists.whitelist
|
||||||
# assert whitelist == expected
|
assert allowlist == allowlist_result
|
||||||
|
Loading…
Reference in New Issue
Block a user