mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-14 20:23:57 +00:00
making list of categories available
This commit is contained in:
parent
50f07e7b11
commit
0dbe507b26
|
@ -38,6 +38,11 @@ class __OptionPairlistParameter(__PairlistParameterBase):
|
||||||
default: Union[str, None]
|
default: Union[str, None]
|
||||||
options: List[str]
|
options: List[str]
|
||||||
|
|
||||||
|
class __ListPairListParamenter(__PairlistParameterBase):
|
||||||
|
type: Literal["list"]
|
||||||
|
default: Union[List[str], None]
|
||||||
|
options: List[str]
|
||||||
|
|
||||||
|
|
||||||
class __BoolPairlistParameter(__PairlistParameterBase):
|
class __BoolPairlistParameter(__PairlistParameterBase):
|
||||||
type: Literal["boolean"]
|
type: Literal["boolean"]
|
||||||
|
@ -49,6 +54,7 @@ PairlistParameter = Union[
|
||||||
__StringPairlistParameter,
|
__StringPairlistParameter,
|
||||||
__OptionPairlistParameter,
|
__OptionPairlistParameter,
|
||||||
__BoolPairlistParameter,
|
__BoolPairlistParameter,
|
||||||
|
__ListPairListParamenter
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,12 +74,12 @@ class IPairList(LoggingMixin, ABC):
|
||||||
supports_backtesting: SupportsBacktesting = SupportsBacktesting.NO
|
supports_backtesting: SupportsBacktesting = SupportsBacktesting.NO
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
exchange: Exchange,
|
exchange: Exchange,
|
||||||
pairlistmanager,
|
pairlistmanager,
|
||||||
config: Config,
|
config: Config,
|
||||||
pairlistconfig: Dict[str, Any],
|
pairlistconfig: Dict[str, Any],
|
||||||
pairlist_pos: int,
|
pairlist_pos: int,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
:param exchange: Exchange instance
|
:param exchange: Exchange instance
|
||||||
|
@ -213,7 +219,7 @@ class IPairList(LoggingMixin, ABC):
|
||||||
return self._pairlistmanager.verify_blacklist(pairlist, logmethod)
|
return self._pairlistmanager.verify_blacklist(pairlist, logmethod)
|
||||||
|
|
||||||
def verify_whitelist(
|
def verify_whitelist(
|
||||||
self, pairlist: List[str], logmethod, keep_invalid: bool = False
|
self, pairlist: List[str], logmethod, keep_invalid: bool = False
|
||||||
) -> List[str]:
|
) -> List[str]:
|
||||||
"""
|
"""
|
||||||
Proxy method to verify_whitelist for easy access for child classes.
|
Proxy method to verify_whitelist for easy access for child classes.
|
||||||
|
|
|
@ -14,7 +14,6 @@ from freqtrade.exchange.exchange_types import Tickers
|
||||||
from freqtrade.plugins.pairlist.IPairList import IPairList, PairlistParameter, SupportsBacktesting
|
from freqtrade.plugins.pairlist.IPairList import IPairList, PairlistParameter, SupportsBacktesting
|
||||||
from freqtrade.util.coin_gecko import FtCoinGeckoApi
|
from freqtrade.util.coin_gecko import FtCoinGeckoApi
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,7 +34,7 @@ class MarketCapPairList(IPairList):
|
||||||
self._number_assets = self._pairlistconfig["number_assets"]
|
self._number_assets = self._pairlistconfig["number_assets"]
|
||||||
self._max_rank = self._pairlistconfig.get("max_rank", 30)
|
self._max_rank = self._pairlistconfig.get("max_rank", 30)
|
||||||
self._refresh_period = self._pairlistconfig.get("refresh_period", 86400)
|
self._refresh_period = self._pairlistconfig.get("refresh_period", 86400)
|
||||||
self._category = self._pairlistconfig.get("category", None)
|
self._categories = self._pairlistconfig.get("categories", [])
|
||||||
self._marketcap_cache: TTLCache = TTLCache(maxsize=1, ttl=self._refresh_period)
|
self._marketcap_cache: TTLCache = TTLCache(maxsize=1, ttl=self._refresh_period)
|
||||||
self._def_candletype = self._config["candle_type_def"]
|
self._def_candletype = self._config["candle_type_def"]
|
||||||
|
|
||||||
|
@ -46,14 +45,14 @@ class MarketCapPairList(IPairList):
|
||||||
is_demo=_coingecko_config.get("is_demo", True),
|
is_demo=_coingecko_config.get("is_demo", True),
|
||||||
)
|
)
|
||||||
|
|
||||||
if self._category:
|
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]
|
||||||
|
|
||||||
if self._category not in category_ids:
|
for category in self._categories:
|
||||||
raise OperationalException(
|
if category not in category_ids:
|
||||||
f"category not in coingecko category list you can choose from {category_ids}"
|
raise OperationalException(
|
||||||
)
|
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.")
|
||||||
|
@ -95,11 +94,11 @@ class MarketCapPairList(IPairList):
|
||||||
"description": "Max rank of assets",
|
"description": "Max rank of assets",
|
||||||
"help": "Maximum rank of assets to use from the pairlist",
|
"help": "Maximum rank of assets to use from the pairlist",
|
||||||
},
|
},
|
||||||
"category": {
|
"categories": {
|
||||||
"type": "string",
|
"type": "list",
|
||||||
"default": None,
|
"default": [],
|
||||||
"description": "The Category",
|
"description": "The Categories to be set",
|
||||||
"help": "Th Category of the coin e.g layer-1 default None",
|
"help": "The Category of the coin e.g layer-1 default [] (https://www.coingecko.com/en/categories)",
|
||||||
},
|
},
|
||||||
"refresh_period": {
|
"refresh_period": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
|
@ -148,16 +147,32 @@ class MarketCapPairList(IPairList):
|
||||||
"""
|
"""
|
||||||
marketcap_list = self._marketcap_cache.get("marketcap")
|
marketcap_list = self._marketcap_cache.get("marketcap")
|
||||||
|
|
||||||
|
default_kwargs = {
|
||||||
|
"vs_currency": "usd",
|
||||||
|
"order": "market_cap_desc",
|
||||||
|
"per_page": "250",
|
||||||
|
"page": "1",
|
||||||
|
"sparkline": "false",
|
||||||
|
"locale": "en",
|
||||||
|
}
|
||||||
|
|
||||||
if marketcap_list is None:
|
if marketcap_list is None:
|
||||||
data = self._coingecko.get_coins_markets(
|
data = []
|
||||||
vs_currency="usd",
|
|
||||||
order="market_cap_desc",
|
if not self._categories:
|
||||||
per_page="250",
|
data = self._coingecko.get_coins_markets(
|
||||||
page="1",
|
**default_kwargs
|
||||||
sparkline="false",
|
)
|
||||||
locale="en",
|
else:
|
||||||
**({"category": self._category} if self._category else {}),
|
for category in self._categories:
|
||||||
)
|
category_data = self._coingecko.get_coins_markets(
|
||||||
|
**default_kwargs,
|
||||||
|
**({"category": category} if category else {})
|
||||||
|
)
|
||||||
|
data += category_data
|
||||||
|
|
||||||
|
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]
|
||||||
self._marketcap_cache["marketcap"] = marketcap_list
|
self._marketcap_cache["marketcap"] = marketcap_list
|
||||||
|
@ -170,11 +185,11 @@ class MarketCapPairList(IPairList):
|
||||||
if market == "futures":
|
if market == "futures":
|
||||||
pair_format += f":{self._stake_currency.upper()}"
|
pair_format += f":{self._stake_currency.upper()}"
|
||||||
|
|
||||||
top_marketcap = marketcap_list[: self._max_rank :]
|
top_marketcap = marketcap_list[: self._max_rank:]
|
||||||
|
|
||||||
for mc_pair in top_marketcap:
|
for mc_pair in top_marketcap:
|
||||||
test_pair = f"{mc_pair.upper()}/{pair_format}"
|
test_pair = f"{mc_pair.upper()}/{pair_format}"
|
||||||
if test_pair in pairlist:
|
if test_pair in pairlist and test_pair not in filtered_pairlist:
|
||||||
filtered_pairlist.append(test_pair)
|
filtered_pairlist.append(test_pair)
|
||||||
if len(filtered_pairlist) == self._number_assets:
|
if len(filtered_pairlist) == self._number_assets:
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue
Block a user