stable/freqtrade/pairlist/StaticPairList.py

91 lines
2.8 KiB
Python
Raw Normal View History

2018-11-30 05:34:56 +00:00
"""
Static List provider
Provides lists as configured in config.json
"""
import logging
2018-12-03 18:29:35 +00:00
from typing import List
2018-11-30 05:34:56 +00:00
logger = logging.getLogger(__name__)
class StaticPairList(object):
2018-11-30 05:34:56 +00:00
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', [])
2018-11-30 05:54:20 +00:00
# self.refresh_whitelist()
2018-11-30 05:34:56 +00:00
2018-12-03 19:31:25 +00:00
@property
def name(self) -> str:
"""
Gets name of the class
-> no need to overwrite in subclasses
"""
return self.__class__.__name__
2018-11-30 05:34:56 +00:00
@property
def whitelist(self) -> List[str]:
2018-12-03 19:31:25 +00:00
"""
Has the current whitelist
-> no need to overwrite in subclasses
"""
2018-11-30 05:34:56 +00:00
return self._whitelist
@property
def blacklist(self) -> List[str]:
2018-12-03 19:31:25 +00:00
"""
Has the current blacklist
-> no need to overwrite in subclasses
"""
2018-11-30 05:34:56 +00:00
return self._blacklist
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
"""
return f"{self.name}: {self.whitelist}"
def refresh_whitelist(self) -> None:
2018-11-30 05:34:56 +00:00
"""
2018-11-30 06:06:02 +00:00
Refreshes whitelist and assigns it to self._whitelist
2018-11-30 05:34:56 +00:00
"""
self._whitelist = self._validate_whitelist(self._config['exchange']['pair_whitelist'])
2018-11-30 05:34:56 +00:00
def _validate_whitelist(self, whitelist: List[str]) -> List[str]:
2018-11-30 05:34:56 +00:00
"""
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
"""
sanitized_whitelist = whitelist
markets = self._freqtrade.exchange.get_markets()
# Filter to markets in stake currency
markets = [m for m in markets if m['quote'] == self._config['stake_currency']]
known_pairs = set()
for market in markets:
pair = market['symbol']
# pair is not int the generated dynamic market, or in the blacklist ... ignore it
if pair not in whitelist or pair in self.blacklist:
continue
# else the pair is valid
known_pairs.add(pair)
# Market is not active
if not market['active']:
sanitized_whitelist.remove(pair)
logger.info(
'Ignoring %s from whitelist. Market is not active.',
pair
)
# We need to remove pairs that are unknown
return [x for x in sanitized_whitelist if x in known_pairs]