Simplify VolumePairList
This commit is contained in:
parent
2924b70fd7
commit
f0c3a0d2f8
@ -27,6 +27,7 @@ class VolumePairList(IPairList):
|
|||||||
f'`number_assets` not specified. Please check your configuration '
|
f'`number_assets` not specified. Please check your configuration '
|
||||||
'for "pairlist.config.number_assets"')
|
'for "pairlist.config.number_assets"')
|
||||||
|
|
||||||
|
self._stake_currency = config['stake_currency']
|
||||||
self._number_pairs = self._pairlistconfig['number_assets']
|
self._number_pairs = self._pairlistconfig['number_assets']
|
||||||
self._sort_key = self._pairlistconfig.get('sort_key', 'quoteVolume')
|
self._sort_key = self._pairlistconfig.get('sort_key', 'quoteVolume')
|
||||||
self._min_value = self._pairlistconfig.get('min_value', 0)
|
self._min_value = self._pairlistconfig.get('min_value', 0)
|
||||||
@ -79,9 +80,7 @@ class VolumePairList(IPairList):
|
|||||||
(self._last_refresh + self.refresh_period < datetime.now().timestamp())):
|
(self._last_refresh + self.refresh_period < datetime.now().timestamp())):
|
||||||
|
|
||||||
self._last_refresh = int(datetime.now().timestamp())
|
self._last_refresh = int(datetime.now().timestamp())
|
||||||
pairs = self._gen_pair_whitelist(pairlist, tickers,
|
pairs = self._gen_pair_whitelist(pairlist, tickers)
|
||||||
self._config['stake_currency'],
|
|
||||||
self._sort_key, self._min_value)
|
|
||||||
else:
|
else:
|
||||||
pairs = pairlist
|
pairs = pairlist
|
||||||
|
|
||||||
@ -89,29 +88,29 @@ class VolumePairList(IPairList):
|
|||||||
|
|
||||||
return pairs
|
return pairs
|
||||||
|
|
||||||
def _gen_pair_whitelist(self, pairlist: List[str], tickers: Dict,
|
def _gen_pair_whitelist(self, pairlist: List[str], tickers: Dict) -> List[str]:
|
||||||
base_currency: str, key: str, min_val: int) -> List[str]:
|
|
||||||
"""
|
"""
|
||||||
Updates the whitelist with with a dynamically generated list
|
Updates the whitelist with with a dynamically generated list
|
||||||
:param base_currency: base currency as str
|
:param pairlist: pairlist to filter or sort
|
||||||
:param key: sort key (defaults to 'quoteVolume')
|
|
||||||
:param tickers: Tickers (from exchange.get_tickers()).
|
:param tickers: Tickers (from exchange.get_tickers()).
|
||||||
:return: List of pairs
|
:return: List of pairs
|
||||||
"""
|
"""
|
||||||
if self._pairlist_pos == 0:
|
if self._pairlist_pos == 0:
|
||||||
# If VolumePairList is the first in the list, use fresh pairlist
|
# If VolumePairList is the first in the list, use fresh pairlist
|
||||||
# Check if pair quote currency equals to the stake currency.
|
# Check if pair quote currency equals to the stake currency.
|
||||||
filtered_tickers = [v for k, v in tickers.items()
|
filtered_tickers = [
|
||||||
if (self._exchange.get_pair_quote_currency(k) == base_currency
|
v for k, v in tickers.items()
|
||||||
and v[key] is not None)]
|
if (self._exchange.get_pair_quote_currency(k) == self._stake_currency
|
||||||
|
and v[self._sort_key] is not None)]
|
||||||
else:
|
else:
|
||||||
# If other pairlist is in front, use the incoming pairlist.
|
# If other pairlist is in front, use the incoming pairlist.
|
||||||
filtered_tickers = [v for k, v in tickers.items() if k in pairlist]
|
filtered_tickers = [v for k, v in tickers.items() if k in pairlist]
|
||||||
|
|
||||||
if min_val > 0:
|
if self._min_value > 0:
|
||||||
filtered_tickers = [v for v in filtered_tickers if v[key] > min_val]
|
filtered_tickers = [
|
||||||
|
v for v in filtered_tickers if v[self._sort_key] > self._min_value]
|
||||||
|
|
||||||
sorted_tickers = sorted(filtered_tickers, reverse=True, key=lambda t: t[key])
|
sorted_tickers = sorted(filtered_tickers, reverse=True, key=lambda t: t[self._sort_key])
|
||||||
|
|
||||||
# Validate whitelist to only have active market pairs
|
# Validate whitelist to only have active market pairs
|
||||||
pairs = self._whitelist_for_active_markets([s['symbol'] for s in sorted_tickers])
|
pairs = self._whitelist_for_active_markets([s['symbol'] for s in sorted_tickers])
|
||||||
|
@ -206,6 +206,7 @@ def test_VolumePairList_whitelist_gen(mocker, whitelist_conf, shitcoinmarkets, t
|
|||||||
pairlists, base_currency, whitelist_result,
|
pairlists, base_currency, whitelist_result,
|
||||||
caplog) -> None:
|
caplog) -> None:
|
||||||
whitelist_conf['pairlists'] = pairlists
|
whitelist_conf['pairlists'] = pairlists
|
||||||
|
whitelist_conf['stake_currency'] = base_currency
|
||||||
|
|
||||||
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, whitelist_conf)
|
||||||
@ -215,7 +216,6 @@ def test_VolumePairList_whitelist_gen(mocker, whitelist_conf, shitcoinmarkets, t
|
|||||||
markets=PropertyMock(return_value=shitcoinmarkets),
|
markets=PropertyMock(return_value=shitcoinmarkets),
|
||||||
)
|
)
|
||||||
|
|
||||||
freqtrade.config['stake_currency'] = base_currency
|
|
||||||
freqtrade.pairlists.refresh_pairlist()
|
freqtrade.pairlists.refresh_pairlist()
|
||||||
whitelist = freqtrade.pairlists.whitelist
|
whitelist = freqtrade.pairlists.whitelist
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user