mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-12-15 20:31:43 +00:00
add blacklist mode
This commit is contained in:
@@ -25,14 +25,16 @@ class MarketCapPairList(IPairList):
|
|||||||
def __init__(self, *args, **kwargs) -> None:
|
def __init__(self, *args, **kwargs) -> None:
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
if "number_assets" not in self._pairlistconfig:
|
self._mode = self._pairlistconfig.get("mode", "whitelist")
|
||||||
|
|
||||||
|
if (self._mode == "whitelist") and ("number_assets" not in self._pairlistconfig):
|
||||||
raise OperationalException(
|
raise OperationalException(
|
||||||
"`number_assets` not specified. Please check your configuration "
|
"`number_assets` not specified. Please check your configuration "
|
||||||
'for "pairlist.config.number_assets"'
|
'for "pairlist.config.number_assets"'
|
||||||
)
|
)
|
||||||
|
|
||||||
self._stake_currency = self._config["stake_currency"]
|
self._stake_currency = self._config["stake_currency"]
|
||||||
self._number_assets = self._pairlistconfig["number_assets"]
|
self._number_assets = self._pairlistconfig.get("number_assets", 30)
|
||||||
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._categories = self._pairlistconfig.get("categories", [])
|
self._categories = self._pairlistconfig.get("categories", [])
|
||||||
@@ -78,7 +80,9 @@ class MarketCapPairList(IPairList):
|
|||||||
"""
|
"""
|
||||||
num = self._number_assets
|
num = self._number_assets
|
||||||
rank = self._max_rank
|
rank = self._max_rank
|
||||||
msg = f"{self.name} - {num} pairs placed within top {rank} market cap."
|
mode = self._mode
|
||||||
|
pair_text = num if (mode == "whitelist") else "blacklisting"
|
||||||
|
msg = f"{self.name} - {pair_text} pairs placed within top {rank} market cap."
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -115,6 +119,12 @@ class MarketCapPairList(IPairList):
|
|||||||
"description": "Refresh period",
|
"description": "Refresh period",
|
||||||
"help": "Refresh period in seconds",
|
"help": "Refresh period in seconds",
|
||||||
},
|
},
|
||||||
|
"mode": {
|
||||||
|
"type": "string",
|
||||||
|
"default": "whitelist",
|
||||||
|
"description": "Mode of operation",
|
||||||
|
"help": "Mode of operation (whitelist/blacklist)",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_markets_exchange(self):
|
def get_markets_exchange(self):
|
||||||
@@ -186,6 +196,9 @@ class MarketCapPairList(IPairList):
|
|||||||
:return: new whitelist
|
:return: new whitelist
|
||||||
"""
|
"""
|
||||||
marketcap_list = self._marketcap_cache.get("marketcap")
|
marketcap_list = self._marketcap_cache.get("marketcap")
|
||||||
|
mode = self._mode
|
||||||
|
is_whitelist_mode = mode == "whitelist"
|
||||||
|
filtered_pairlist: list[str] = []
|
||||||
|
|
||||||
default_kwargs = {
|
default_kwargs = {
|
||||||
"vs_currency": "usd",
|
"vs_currency": "usd",
|
||||||
@@ -219,12 +232,10 @@ class MarketCapPairList(IPairList):
|
|||||||
self._marketcap_cache["marketcap"] = marketcap_list
|
self._marketcap_cache["marketcap"] = marketcap_list
|
||||||
|
|
||||||
if marketcap_list:
|
if marketcap_list:
|
||||||
filtered_pairlist: list[str] = []
|
|
||||||
|
|
||||||
market = self._exchange._config["trading_mode"]
|
market = self._exchange._config["trading_mode"]
|
||||||
pair_format = f"{self._stake_currency.upper()}"
|
pair_format = f"{self._stake_currency.upper()}" + (
|
||||||
if market == "futures":
|
f":{self._stake_currency.upper()}" if market == "futures" else ""
|
||||||
pair_format += f":{self._stake_currency.upper()}"
|
)
|
||||||
|
|
||||||
top_marketcap = marketcap_list[: self._max_rank :]
|
top_marketcap = marketcap_list[: self._max_rank :]
|
||||||
markets = self.get_markets_exchange()
|
markets = self.get_markets_exchange()
|
||||||
@@ -234,13 +245,16 @@ class MarketCapPairList(IPairList):
|
|||||||
resolved = self.resolve_marketcap_pair(pair, pairlist, markets, filtered_pairlist)
|
resolved = self.resolve_marketcap_pair(pair, pairlist, markets, filtered_pairlist)
|
||||||
|
|
||||||
if resolved:
|
if resolved:
|
||||||
|
if not is_whitelist_mode:
|
||||||
|
pairlist.remove(resolved)
|
||||||
|
continue
|
||||||
|
|
||||||
filtered_pairlist.append(resolved)
|
filtered_pairlist.append(resolved)
|
||||||
|
if len(filtered_pairlist) == self._number_assets:
|
||||||
|
break
|
||||||
|
|
||||||
if len(filtered_pairlist) == self._number_assets:
|
if not is_whitelist_mode:
|
||||||
break
|
return pairlist
|
||||||
|
|
||||||
if len(filtered_pairlist) > 0:
|
|
||||||
return filtered_pairlist
|
|
||||||
|
|
||||||
# If no pairs are found, return the original pairlist
|
# If no pairs are found, return the original pairlist
|
||||||
return []
|
return filtered_pairlist
|
||||||
|
|||||||
Reference in New Issue
Block a user