2018-12-05 19:44:56 +00:00
|
|
|
"""
|
|
|
|
Static List provider
|
|
|
|
|
|
|
|
Provides lists as configured in config.json
|
|
|
|
|
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
from typing import List
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class IPairList(ABC):
|
|
|
|
|
|
|
|
def __init__(self, freqtrade, config: dict) -> None:
|
|
|
|
self._freqtrade = freqtrade
|
|
|
|
self._config = config
|
|
|
|
self._whitelist = self._config['exchange']['pair_whitelist']
|
|
|
|
self._blacklist = self._config['exchange'].get('pair_blacklist', [])
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self) -> str:
|
|
|
|
"""
|
|
|
|
Gets name of the class
|
|
|
|
-> no need to overwrite in subclasses
|
|
|
|
"""
|
|
|
|
return self.__class__.__name__
|
|
|
|
|
|
|
|
@property
|
|
|
|
def whitelist(self) -> List[str]:
|
|
|
|
"""
|
|
|
|
Has the current whitelist
|
|
|
|
-> no need to overwrite in subclasses
|
|
|
|
"""
|
|
|
|
return self._whitelist
|
|
|
|
|
|
|
|
@property
|
|
|
|
def blacklist(self) -> List[str]:
|
|
|
|
"""
|
|
|
|
Has the current blacklist
|
|
|
|
-> no need to overwrite in subclasses
|
|
|
|
"""
|
|
|
|
return self._blacklist
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def short_desc(self) -> str:
|
|
|
|
"""
|
|
|
|
Short whitelist method description - used for startup-messages
|
|
|
|
-> Please overwrite in subclasses
|
|
|
|
"""
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def refresh_pairlist(self) -> None:
|
|
|
|
"""
|
|
|
|
Refreshes pairlists and assigns them to self._whitelist and self._blacklist respectively
|
|
|
|
-> Please overwrite in subclasses
|
|
|
|
"""
|
|
|
|
|
|
|
|
def _validate_whitelist(self, whitelist: List[str]) -> List[str]:
|
|
|
|
"""
|
|
|
|
Check available markets and remove pair from whitelist if necessary
|
|
|
|
:param whitelist: the sorted list (based on BaseVolume) of pairs the user might want to
|
|
|
|
trade
|
|
|
|
:return: the list of pairs the user wants to trade without the one unavailable or
|
|
|
|
black_listed
|
|
|
|
"""
|
2019-03-05 18:45:10 +00:00
|
|
|
markets = self._freqtrade.exchange.markets
|
2018-12-05 19:44:56 +00:00
|
|
|
|
|
|
|
# Filter to markets in stake currency
|
2019-03-06 21:42:05 +00:00
|
|
|
stake_pairs = [pair for pair in markets if # pair.endswith(self._config['stake_currency'])
|
|
|
|
markets[pair]["quote"] == self._config['stake_currency']]
|
2018-12-05 19:44:56 +00:00
|
|
|
|
2019-03-06 21:42:05 +00:00
|
|
|
sanitized_whitelist = set()
|
2019-03-05 20:23:55 +00:00
|
|
|
for pair in whitelist:
|
2019-03-02 17:53:42 +00:00
|
|
|
# pair is not in the generated dynamic market, or in the blacklist ... ignore it
|
2019-03-05 20:23:55 +00:00
|
|
|
if pair in self.blacklist or pair not in stake_pairs:
|
2018-12-05 19:44:56 +00:00
|
|
|
continue
|
2019-03-05 20:23:55 +00:00
|
|
|
# Check if market is active
|
|
|
|
market = markets[pair]
|
2018-12-05 19:44:56 +00:00
|
|
|
if not market['active']:
|
|
|
|
logger.info(
|
|
|
|
'Ignoring %s from whitelist. Market is not active.',
|
|
|
|
pair
|
|
|
|
)
|
2019-03-05 20:23:55 +00:00
|
|
|
continue
|
2019-03-06 21:42:05 +00:00
|
|
|
sanitized_whitelist.add(pair)
|
2018-12-05 19:44:56 +00:00
|
|
|
|
|
|
|
# We need to remove pairs that are unknown
|
2019-03-06 21:42:05 +00:00
|
|
|
return list(sanitized_whitelist)
|