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] default: Union[str, None]
options: List[str] options: List[str]
class __ListPairListParamenter(__PairlistParameterBase): class __ListPairListParamenter(__PairlistParameterBase):
type: Literal["list"] type: Literal["list"]
default: Union[List[str], None] default: Union[List[str], None]
@ -54,7 +55,7 @@ PairlistParameter = Union[
__StringPairlistParameter, __StringPairlistParameter,
__OptionPairlistParameter, __OptionPairlistParameter,
__BoolPairlistParameter, __BoolPairlistParameter,
__ListPairListParamenter __ListPairListParamenter,
] ]

View File

@ -47,12 +47,13 @@ class MarketCapPairList(IPairList):
if self._categories: if self._categories:
categories = self._coingecko.get_coins_categories_list() 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: for category in self._categories:
if category not in category_ids: if category not in category_ids:
raise OperationalException( 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: if self._max_rank > 250:
raise OperationalException("This filter only support marketcap rank up to 250.") raise OperationalException("This filter only support marketcap rank up to 250.")
@ -160,18 +161,15 @@ class MarketCapPairList(IPairList):
data = [] data = []
if not self._categories: if not self._categories:
data = self._coingecko.get_coins_markets( data = self._coingecko.get_coins_markets(**default_kwargs)
**default_kwargs
)
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(
**default_kwargs, **default_kwargs, **({"category": category} if category else {})
**({"category": category} if category else {})
) )
data += category_data 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: if data:
marketcap_list = [row["symbol"] for row in data] marketcap_list = [row["symbol"] for row in data]