Fix correct ticker type

This commit is contained in:
Matthias
2019-11-09 13:40:36 +01:00
parent 870966dcd0
commit d7262c0b4e
7 changed files with 65 additions and 43 deletions

View File

@@ -46,7 +46,7 @@ class IPairList(ABC):
"""
@abstractmethod
def filter_pairlist(self, pairlist: List[str], tickers: List[Dict]) -> List[str]:
def filter_pairlist(self, pairlist: List[str], tickers: Dict) -> List[str]:
"""
Filters and sorts pairlist and returns the whitelist again.
Called on each bot iteration - please use internal caching if necessary
@@ -97,5 +97,6 @@ class IPairList(ABC):
if pair not in sanitized_whitelist:
sanitized_whitelist.append(pair)
sanitized_whitelist = self._verify_blacklist(sanitized_whitelist)
# We need to remove pairs that are unknown
return sanitized_whitelist

View File

@@ -46,7 +46,7 @@ class LowPriceFilter(IPairList):
return False
return True
def filter_pairlist(self, pairlist: List[str], tickers: List[Dict]) -> List[str]:
def filter_pairlist(self, pairlist: List[str], tickers: Dict) -> List[str]:
"""
Filters and sorts pairlist and returns the whitelist again.
@@ -57,7 +57,9 @@ class LowPriceFilter(IPairList):
"""
# Copy list since we're modifying this list
for p in deepcopy(pairlist):
ticker = [t for t in tickers if t['symbol'] == p][0]
ticker = tickers.get(p)
if not ticker:
pairlist.remove(p)
# Filter out assets which would not allow setting a stoploss
if self._low_price_percent and not self._validate_ticker_lowprice(ticker):

View File

@@ -44,7 +44,7 @@ class PrecisionFilter(IPairList):
return False
return True
def filter_pairlist(self, pairlist: List[str], tickers: List[Dict]) -> List[str]:
def filter_pairlist(self, pairlist: List[str], tickers: Dict) -> List[str]:
"""
Filters and sorts pairlists and assigns and returns them again.
"""
@@ -53,9 +53,9 @@ class PrecisionFilter(IPairList):
stoploss = 1 - abs(self._config.get('stoploss'))
# Copy list since we're modifying this list
for p in deepcopy(pairlist):
ticker = [t for t in tickers if t['symbol'] == p][0]
ticker = tickers.get(p)
# Filter out assets which would not allow setting a stoploss
if (stoploss and not self._validate_precision_filter(ticker, stoploss)):
if not ticker or (stoploss and not self._validate_precision_filter(ticker, stoploss)):
pairlist.remove(p)
continue

View File

@@ -33,7 +33,7 @@ class StaticPairList(IPairList):
"""
return f"{self.name}"
def filter_pairlist(self, pairlist: List[str], tickers: List[Dict]) -> List[str]:
def filter_pairlist(self, pairlist: List[str], tickers: Dict) -> List[str]:
"""
Filters and sorts pairlist and returns the whitelist again.
Called on each bot iteration - please use internal caching if necessary

View File

@@ -5,10 +5,9 @@ Provides lists as configured in config.json
"""
import logging
from datetime import datetime
from typing import Dict, List
from cachetools import TTLCache, cached
from freqtrade import OperationalException
from freqtrade.pairlist.IPairList import IPairList
@@ -28,6 +27,7 @@ class VolumePairList(IPairList):
'for "pairlist.config.number_assets"')
self._number_pairs = self._pairlistconfig['number_assets']
self._sort_key = self._pairlistconfig.get('sort_key', 'quoteVolume')
self._ttl = self._pairlistconfig.get('ttl', 1800)
if not self._exchange.exchange_has('fetchTickers'):
raise OperationalException(
@@ -37,6 +37,7 @@ class VolumePairList(IPairList):
if not self._validate_keys(self._sort_key):
raise OperationalException(
f'key {self._sort_key} not in {SORT_VALUES}')
self._last_refresh = 0
@property
def needstickers(self) -> bool:
@@ -56,7 +57,7 @@ class VolumePairList(IPairList):
"""
return f"{self.name} - top {self._pairlistconfig['number_assets']} volume pairs."
def filter_pairlist(self, pairlist: List[str], tickers: List[Dict]) -> List[str]:
def filter_pairlist(self, pairlist: List[str], tickers: Dict) -> List[str]:
"""
Filters and sorts pairlist and returns the whitelist again.
Called on each bot iteration - please use internal caching if necessary
@@ -65,10 +66,17 @@ class VolumePairList(IPairList):
:return: new whitelist
"""
# Generate dynamic whitelist
return self._gen_pair_whitelist(self._config['stake_currency'], self._sort_key)
if self._last_refresh + self._ttl < datetime.now().timestamp():
self._last_refresh = datetime.now().timestamp()
return self._gen_pair_whitelist(pairlist,
tickers,
self._config['stake_currency'],
self._sort_key,
)
else:
return pairlist
@cached(TTLCache(maxsize=1, ttl=1800))
def _gen_pair_whitelist(self, base_currency: str, key: str) -> List[str]:
def _gen_pair_whitelist(self, pairlist, tickers, base_currency: str, key: str) -> List[str]:
"""
Updates the whitelist with with a dynamically generated list
:param base_currency: base currency as str
@@ -77,7 +85,6 @@ class VolumePairList(IPairList):
:return: List of pairs
"""
tickers = self._exchange.get_tickers()
# check length so that we make sure that '/' is actually in the string
tickers = [v for k, v in tickers.items()
if (len(k.split('/')) == 2 and k.split('/')[1] == base_currency

View File

@@ -64,7 +64,7 @@ class PairListManager():
pairlist = self._whitelist.copy()
# tickers should be cached to avoid calling the exchange on each call.
tickers: List[Dict] = []
tickers: Dict = {}
if self._tickers_needed:
tickers = self._exchange.get_tickers()