mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
69 lines
2.0 KiB
Python
69 lines
2.0 KiB
Python
|
"""
|
||
|
Static List provider
|
||
|
|
||
|
Provides lists as configured in config.json
|
||
|
|
||
|
"""
|
||
|
import logging
|
||
|
from copy import deepcopy
|
||
|
from typing import List
|
||
|
|
||
|
from freqtrade.pairlist.IPairList import IPairList
|
||
|
from freqtrade.resolvers import PairListResolver
|
||
|
|
||
|
logger = logging.getLogger(__name__)
|
||
|
|
||
|
|
||
|
class PairListManager():
|
||
|
|
||
|
def __init__(self, exchange, config: dict) -> None:
|
||
|
self._exchange = exchange
|
||
|
self._config = config
|
||
|
self._whitelist = self._config['exchange'].get('pair_whitelist')
|
||
|
self._blacklist = self._config['exchange'].get('pair_blacklist', [])
|
||
|
self._pairlists: List[IPairList] = []
|
||
|
|
||
|
for pl in self._config.get('pairlists', [{'method': "StaticPairList"}]):
|
||
|
pairl = PairListResolver(pl.get('method'),
|
||
|
exchange, config,
|
||
|
pl.get('config')).pairlist
|
||
|
self._pairlists.append(pairl)
|
||
|
|
||
|
@property
|
||
|
def whitelist(self) -> List[str]:
|
||
|
"""
|
||
|
Has the current whitelist
|
||
|
"""
|
||
|
return self._whitelist
|
||
|
|
||
|
@property
|
||
|
def blacklist(self) -> List[str]:
|
||
|
"""
|
||
|
Has the current blacklist
|
||
|
-> no need to overwrite in subclasses
|
||
|
"""
|
||
|
return self._blacklist
|
||
|
|
||
|
def refresh_pairlist(self) -> None:
|
||
|
"""
|
||
|
Run pairlist through all pairlists.
|
||
|
"""
|
||
|
|
||
|
pairlist = self._whitelist.copy()
|
||
|
|
||
|
# tickers should be cached to avoid calling the exchange on each call.
|
||
|
tickers = self._exchange.get_tickers()
|
||
|
for pl in self._pairlists:
|
||
|
pl.filter_pairlist(pairlist, tickers)
|
||
|
|
||
|
pairlist = self._verify_blacklist(pairlist)
|
||
|
self._whitelist = pairlist
|
||
|
|
||
|
def _verify_blacklist(self, pairlist: List[str]) -> List[str]:
|
||
|
|
||
|
for pair in deepcopy(pairlist):
|
||
|
if pair in self.blacklist:
|
||
|
logger.warning(f"Pair {pair} in your blacklist. Removing it from whitelist...")
|
||
|
pairlist.remove(pair)
|
||
|
return pairlist
|