feat: enhance data fetching logic with pagination to increase market cap rank limit
This commit is contained in:
@@ -5,6 +5,7 @@ Provides dynamic pair list based on Market Cap
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import math
|
||||||
|
|
||||||
from cachetools import TTLCache
|
from cachetools import TTLCache
|
||||||
|
|
||||||
@@ -56,8 +57,8 @@ class MarketCapPairList(IPairList):
|
|||||||
f"You can choose from {category_ids}"
|
f"You can choose from {category_ids}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if self._max_rank > 250:
|
if self._max_rank > 1000:
|
||||||
raise OperationalException("This filter only support marketcap rank up to 250.")
|
raise OperationalException("This filter only support marketcap rank up to 1000.")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def needstickers(self) -> bool:
|
def needstickers(self) -> bool:
|
||||||
@@ -165,7 +166,11 @@ class MarketCapPairList(IPairList):
|
|||||||
data = []
|
data = []
|
||||||
|
|
||||||
if not self._categories:
|
if not self._categories:
|
||||||
data = self._coingecko.get_coins_markets(**default_kwargs)
|
pages_required = math.ceil(self._max_rank / 250)
|
||||||
|
for page in range(1, pages_required + 1):
|
||||||
|
default_kwargs["page"] = page
|
||||||
|
page_data = self._coingecko.get_coins_markets(**default_kwargs)
|
||||||
|
data.extend(page_data)
|
||||||
else:
|
else:
|
||||||
for category in self._categories:
|
for category in self._categories:
|
||||||
category_data = self._coingecko.get_coins_markets(
|
category_data = self._coingecko.get_coins_markets(
|
||||||
|
|||||||
@@ -2458,10 +2458,10 @@ def test_MarketCapPairList_exceptions(mocker, default_conf_usdt):
|
|||||||
PairListManager(exchange, default_conf_usdt)
|
PairListManager(exchange, default_conf_usdt)
|
||||||
|
|
||||||
default_conf_usdt["pairlists"] = [
|
default_conf_usdt["pairlists"] = [
|
||||||
{"method": "MarketCapPairList", "number_assets": 20, "max_rank": 260}
|
{"method": "MarketCapPairList", "number_assets": 20, "max_rank": 1010}
|
||||||
]
|
]
|
||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
OperationalException, match="This filter only support marketcap rank up to 250."
|
OperationalException, match="This filter only support marketcap rank up to 1000."
|
||||||
):
|
):
|
||||||
PairListManager(exchange, default_conf_usdt)
|
PairListManager(exchange, default_conf_usdt)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user