add mode
This commit is contained in:
@@ -21,7 +21,7 @@ from pycoingecko import CoinGeckoAPI
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
SORT_VALUES = ['quoteVolume']
|
MODE_VALUES = ['top_rank', 'total_assets']
|
||||||
|
|
||||||
|
|
||||||
class MarketCapFilter(IPairList):
|
class MarketCapFilter(IPairList):
|
||||||
@@ -33,23 +33,28 @@ class MarketCapFilter(IPairList):
|
|||||||
pairlist_pos: int) -> None:
|
pairlist_pos: int) -> None:
|
||||||
super().__init__(exchange, pairlistmanager, config, pairlistconfig, pairlist_pos)
|
super().__init__(exchange, pairlistmanager, config, pairlistconfig, pairlist_pos)
|
||||||
|
|
||||||
if 'max_rank' not in self._pairlistconfig:
|
if 'limit' not in self._pairlistconfig:
|
||||||
raise OperationalException(
|
raise OperationalException(
|
||||||
'`max_rank` not specified. Please check your configuration '
|
'`limit` not specified. Please check your configuration '
|
||||||
'for "pairlist.config.max_rank"')
|
'for "pairlist.config.limit"')
|
||||||
|
|
||||||
self._stake_currency = config['stake_currency']
|
self._stake_currency = config['stake_currency']
|
||||||
self._max_rank = self._pairlistconfig['max_rank']
|
self._mode = self._pairlistconfig.get('mode', 'top_rank')
|
||||||
|
self._limit = self._pairlistconfig['limit']
|
||||||
self._refresh_period = self._pairlistconfig.get('refresh_period', 86400)
|
self._refresh_period = self._pairlistconfig.get('refresh_period', 86400)
|
||||||
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']
|
||||||
self._coingekko: CoinGeckoAPI = CoinGeckoAPI()
|
self._coingekko: CoinGeckoAPI = CoinGeckoAPI()
|
||||||
|
|
||||||
if self._max_rank > 250:
|
if self._limit > 250:
|
||||||
raise OperationalException(
|
raise OperationalException(
|
||||||
"This filter only support up to rank 250."
|
"This filter only support up to rank 250."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not self._validate_keys(self._mode):
|
||||||
|
raise OperationalException(
|
||||||
|
f'key {self._mode} not in {MODE_VALUES}')
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def needstickers(self) -> bool:
|
def needstickers(self) -> bool:
|
||||||
@@ -61,13 +66,13 @@ class MarketCapFilter(IPairList):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def _validate_keys(self, key):
|
def _validate_keys(self, key):
|
||||||
return key in SORT_VALUES
|
return key in MODE_VALUES
|
||||||
|
|
||||||
def short_desc(self) -> str:
|
def short_desc(self) -> str:
|
||||||
"""
|
"""
|
||||||
Short whitelist method description - used for startup-messages
|
Short whitelist method description - used for startup-messages
|
||||||
"""
|
"""
|
||||||
return f"{self.name} - Only use top {self._pairlistconfig['max_rank']} market cap pairs."
|
return f"{self.name} - Only use top {self._pairlistconfig['limit']} market cap pairs."
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def description() -> str:
|
def description() -> str:
|
||||||
@@ -76,11 +81,18 @@ class MarketCapFilter(IPairList):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def available_parameters() -> Dict[str, PairlistParameter]:
|
def available_parameters() -> Dict[str, PairlistParameter]:
|
||||||
return {
|
return {
|
||||||
"max_rank": {
|
"limit": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"default": 30,
|
"default": 30,
|
||||||
"description": "Max market cap rank",
|
"description": "Max market cap rank",
|
||||||
"help": "Only use assets that ranked within top max_rank market cap",
|
"help": "Only use assets with high market cap rank",
|
||||||
|
},
|
||||||
|
"mode": {
|
||||||
|
"type": "option",
|
||||||
|
"default": "top_rank",
|
||||||
|
"options": MODE_VALUES,
|
||||||
|
"description": "Mode of number",
|
||||||
|
"help": "How to interpret the number",
|
||||||
},
|
},
|
||||||
"refresh_period": {
|
"refresh_period": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
@@ -156,23 +168,23 @@ class MarketCapFilter(IPairList):
|
|||||||
if can_filter:
|
if can_filter:
|
||||||
filtered_pairlist = []
|
filtered_pairlist = []
|
||||||
|
|
||||||
# option A
|
if self._mode == 'top_rank':
|
||||||
# top_marketcap = marketcap_list[:self._max_rank:]
|
top_marketcap = marketcap_list[:self._limit:]
|
||||||
|
|
||||||
# for pair in pairlist:
|
for pair in pairlist:
|
||||||
# base = pair.split('/')[0]
|
base = pair.split('/')[0]
|
||||||
# if base.lower() in top_marketcap:
|
if base.lower() in top_marketcap:
|
||||||
# filtered_pairlist.append(pair)
|
filtered_pairlist.append(pair)
|
||||||
# else:
|
else:
|
||||||
# logger.info(f"Remove {pair} from whitelist because it's not in "
|
logger.info(f"Remove {pair} from whitelist because it's not ranked "
|
||||||
# f"top {self._max_rank} market cap")
|
f"within top {self._limit} market cap")
|
||||||
|
|
||||||
# option B
|
else:
|
||||||
for mc_pair in marketcap_list:
|
for mc_pair in marketcap_list:
|
||||||
test_pair = f"{mc_pair.upper()}/{self._stake_currency.upper()}"
|
test_pair = f"{mc_pair.upper()}/{self._stake_currency.upper()}"
|
||||||
if test_pair in pairlist:
|
if test_pair in pairlist:
|
||||||
filtered_pairlist.append(test_pair)
|
filtered_pairlist.append(test_pair)
|
||||||
if len(filtered_pairlist) == self._max_rank:
|
if len(filtered_pairlist) == self._limit:
|
||||||
break
|
break
|
||||||
|
|
||||||
if len(filtered_pairlist) > 0:
|
if len(filtered_pairlist) > 0:
|
||||||
|
|||||||
Reference in New Issue
Block a user