Add support for max_value in volume pair list

This commit is contained in:
stevanStevic 2024-03-28 22:20:34 +01:00
parent 78442e36e7
commit 1ec04a8dc8
3 changed files with 20 additions and 0 deletions

View File

@ -81,12 +81,14 @@ Filtering instances (not the first position in the list) will not apply any cach
"number_assets": 20,
"sort_key": "quoteVolume",
"min_value": 0,
"max_value": 8000000,
"refresh_period": 1800
}
],
```
You can define a minimum volume with `min_value` - which will filter out pairs with a volume lower than the specified value in the specified timerange.
In addition to that, you can also define a maximum volume with `max_value` - which will filter out pairs with a volume higher than the specified value in the specified timerange.
##### VolumePairList Advanced mode

View File

@ -41,6 +41,7 @@ class VolumePairList(IPairList):
self._number_pairs = self._pairlistconfig['number_assets']
self._sort_key: Literal['quoteVolume'] = self._pairlistconfig.get('sort_key', 'quoteVolume')
self._min_value = self._pairlistconfig.get('min_value', 0)
self._max_value = self._pairlistconfig.get("max_value", None)
self._refresh_period = self._pairlistconfig.get('refresh_period', 1800)
self._pair_cache: TTLCache = TTLCache(maxsize=1, ttl=self._refresh_period)
self._lookback_days = self._pairlistconfig.get('lookback_days', 0)
@ -139,6 +140,12 @@ class VolumePairList(IPairList):
"description": "Minimum value",
"help": "Minimum value to use for filtering the pairlist.",
},
"max_value": {
"type": "number",
"default": None,
"description": "Maximum value",
"help": "Maximum value to use for filtering the pairlist.",
},
**IPairList.refresh_period_parameter(),
"lookback_days": {
"type": "number",
@ -270,6 +277,9 @@ class VolumePairList(IPairList):
if self._min_value > 0:
filtered_tickers = [
v for v in filtered_tickers if v[self._sort_key] > self._min_value]
if self._max_value is not None:
filtered_tickers = [
v for v in filtered_tickers if v[self._sort_key] < self._max_value]
sorted_tickers = sorted(filtered_tickers, reverse=True, key=lambda t: t[self._sort_key])

View File

@ -406,6 +406,14 @@ def test_VolumePairList_refresh_empty(mocker, markets_empty, whitelist_conf):
([{"method": "VolumePairList", "number_assets": 5,
"sort_key": "quoteVolume", "min_value": 1250}],
"BTC", ['ETH/BTC', 'TKN/BTC', 'LTC/BTC']),
# HOT, XRP and FUEL whitelisted because they are below 1300 quoteVolume.
([{"method": "VolumePairList", "number_assets": 5,
"sort_key": "quoteVolume", "max_value": 1300}],
"BTC", ['XRP/BTC', 'HOT/BTC', 'FUEL/BTC']),
# HOT, XRP whitelisted because they are between 100 and 1300 quoteVolume.
([{"method": "VolumePairList", "number_assets": 5,
"sort_key": "quoteVolume", "min_value": 100, "max_value": 1300}],
"BTC", ['XRP/BTC', 'HOT/BTC']),
# StaticPairlist only
([{"method": "StaticPairList"}],
"BTC", ['ETH/BTC', 'TKN/BTC', 'HOT/BTC']),