This commit is contained in:
Jakub Werner (jakubikan) 2024-09-25 21:22:40 +02:00
parent 514558796b
commit 8aefae3aff
2 changed files with 16 additions and 17 deletions

View File

@ -38,6 +38,7 @@ class __OptionPairlistParameter(__PairlistParameterBase):
default: Union[str, None]
options: List[str]
class __ListPairListParamenter(__PairlistParameterBase):
type: Literal["list"]
default: Union[List[str], None]
@ -54,7 +55,7 @@ PairlistParameter = Union[
__StringPairlistParameter,
__OptionPairlistParameter,
__BoolPairlistParameter,
__ListPairListParamenter
__ListPairListParamenter,
]

View File

@ -47,12 +47,13 @@ class MarketCapPairList(IPairList):
if self._categories:
categories = self._coingecko.get_coins_categories_list()
category_ids = [cat['category_id'] for cat in categories]
category_ids = [cat["category_id"] for cat in categories]
for category in self._categories:
if category not in category_ids:
raise OperationalException(
f"category not in coingecko category list you can choose from {category_ids}")
f"category not in coingecko category list you can choose from {category_ids}"
)
if self._max_rank > 250:
raise OperationalException("This filter only support marketcap rank up to 250.")
@ -160,18 +161,15 @@ class MarketCapPairList(IPairList):
data = []
if not self._categories:
data = self._coingecko.get_coins_markets(
**default_kwargs
)
data = self._coingecko.get_coins_markets(**default_kwargs)
else:
for category in self._categories:
category_data = self._coingecko.get_coins_markets(
**default_kwargs,
**({"category": category} if category else {})
**default_kwargs, **({"category": category} if category else {})
)
data += category_data
data.sort(key=lambda d: float(d['market_cap'] or 0.0), reverse=True)
data.sort(key=lambda d: float(d["market_cap"] or 0.0), reverse=True)
if data:
marketcap_list = [row["symbol"] for row in data]