2018-11-30 05:34:56 +00:00
|
|
|
"""
|
2020-05-17 11:26:21 +00:00
|
|
|
Static Pair List provider
|
2018-11-30 05:34:56 +00:00
|
|
|
|
2020-05-17 11:26:21 +00:00
|
|
|
Provides pair white list as it configured in config
|
|
|
|
"""
|
2024-05-12 14:37:11 +00:00
|
|
|
|
2018-11-30 05:34:56 +00:00
|
|
|
import logging
|
2021-10-19 17:48:56 +00:00
|
|
|
from copy import deepcopy
|
2024-06-09 06:54:48 +00:00
|
|
|
from typing import Dict, List
|
2018-12-05 19:44:56 +00:00
|
|
|
|
2024-09-04 04:42:51 +00:00
|
|
|
from freqtrade.exchange.exchange_types import Tickers
|
2024-06-21 12:09:30 +00:00
|
|
|
from freqtrade.plugins.pairlist.IPairList import IPairList, PairlistParameter, SupportsBacktesting
|
2018-11-30 05:34:56 +00:00
|
|
|
|
2020-05-17 11:26:21 +00:00
|
|
|
|
2018-11-30 05:34:56 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2018-12-05 19:44:56 +00:00
|
|
|
class StaticPairList(IPairList):
|
2023-04-20 16:09:47 +00:00
|
|
|
is_pairlist_generator = True
|
2024-06-21 12:09:30 +00:00
|
|
|
supports_backtesting = SupportsBacktesting.YES
|
2023-04-20 16:09:47 +00:00
|
|
|
|
2024-06-09 06:54:48 +00:00
|
|
|
def __init__(self, *args, **kwargs) -> None:
|
|
|
|
super().__init__(*args, **kwargs)
|
2020-05-29 09:40:05 +00:00
|
|
|
|
2024-05-12 14:37:11 +00:00
|
|
|
self._allow_inactive = self._pairlistconfig.get("allow_inactive", False)
|
2020-11-12 11:29:46 +00:00
|
|
|
|
2019-11-09 06:05:17 +00:00
|
|
|
@property
|
|
|
|
def needstickers(self) -> bool:
|
|
|
|
"""
|
|
|
|
Boolean property defining if tickers are necessary.
|
2020-11-24 19:24:51 +00:00
|
|
|
If no Pairlist requires tickers, an empty Dict is passed
|
2019-11-09 06:05:17 +00:00
|
|
|
as tickers argument to filter_pairlist
|
|
|
|
"""
|
|
|
|
return False
|
|
|
|
|
2018-12-03 19:31:25 +00:00
|
|
|
def short_desc(self) -> str:
|
|
|
|
"""
|
|
|
|
Short whitelist method description - used for startup-messages
|
|
|
|
-> Please overwrite in subclasses
|
|
|
|
"""
|
2019-11-09 06:07:33 +00:00
|
|
|
return f"{self.name}"
|
2018-12-03 19:31:25 +00:00
|
|
|
|
2023-05-28 16:21:23 +00:00
|
|
|
@staticmethod
|
|
|
|
def description() -> str:
|
|
|
|
return "Use pairlist as configured in config."
|
|
|
|
|
2023-04-20 04:58:05 +00:00
|
|
|
@staticmethod
|
|
|
|
def available_parameters() -> Dict[str, PairlistParameter]:
|
|
|
|
return {
|
|
|
|
"allow_inactive": {
|
|
|
|
"type": "boolean",
|
|
|
|
"default": False,
|
|
|
|
"description": "Allow inactive pairs",
|
|
|
|
"help": "Allow inactive pairs to be in the whitelist.",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-10-11 19:33:02 +00:00
|
|
|
def gen_pairlist(self, tickers: Tickers) -> List[str]:
|
2020-05-22 12:03:49 +00:00
|
|
|
"""
|
|
|
|
Generate the pairlist
|
2022-10-10 11:54:13 +00:00
|
|
|
:param tickers: Tickers (from exchange.get_tickers). May be cached.
|
2020-05-22 12:03:49 +00:00
|
|
|
:return: List of pairs
|
|
|
|
"""
|
2024-09-15 07:46:47 +00:00
|
|
|
wl = self.verify_whitelist(
|
|
|
|
self._config["exchange"]["pair_whitelist"], logger.info, keep_invalid=True
|
|
|
|
)
|
2020-11-12 11:29:46 +00:00
|
|
|
if self._allow_inactive:
|
2024-09-15 07:46:47 +00:00
|
|
|
return wl
|
2020-11-12 11:29:46 +00:00
|
|
|
else:
|
2024-09-15 07:48:44 +00:00
|
|
|
# Avoid implicit filtering of "verify_whitelist" to keep
|
|
|
|
# proper warnings in the log
|
2024-09-15 07:46:47 +00:00
|
|
|
return self._whitelist_for_active_markets(wl)
|
2020-05-22 12:03:49 +00:00
|
|
|
|
2022-10-11 19:33:02 +00:00
|
|
|
def filter_pairlist(self, pairlist: List[str], tickers: Tickers) -> List[str]:
|
2018-11-30 05:34:56 +00:00
|
|
|
"""
|
2019-11-09 05:55:16 +00:00
|
|
|
Filters and sorts pairlist and returns the whitelist again.
|
|
|
|
Called on each bot iteration - please use internal caching if necessary
|
|
|
|
:param pairlist: pairlist to filter or sort
|
2022-10-10 11:54:13 +00:00
|
|
|
:param tickers: Tickers (from exchange.get_tickers). May be cached.
|
2019-11-09 05:55:16 +00:00
|
|
|
:return: new whitelist
|
2018-11-30 05:34:56 +00:00
|
|
|
"""
|
2021-10-19 17:48:56 +00:00
|
|
|
pairlist_ = deepcopy(pairlist)
|
2024-05-12 14:37:11 +00:00
|
|
|
for pair in self._config["exchange"]["pair_whitelist"]:
|
2021-10-19 17:48:56 +00:00
|
|
|
if pair not in pairlist_:
|
|
|
|
pairlist_.append(pair)
|
|
|
|
return pairlist_
|