2019-10-30 14:59:52 +00:00
|
|
|
import logging
|
|
|
|
from copy import deepcopy
|
2020-02-02 04:00:40 +00:00
|
|
|
from typing import Any, Dict, List
|
2019-10-30 14:59:52 +00:00
|
|
|
|
2019-11-09 05:55:16 +00:00
|
|
|
from freqtrade.pairlist.IPairList import IPairList
|
2019-10-30 14:59:52 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2019-11-19 05:41:05 +00:00
|
|
|
class PriceFilter(IPairList):
|
2019-10-30 14:59:52 +00:00
|
|
|
|
2020-02-02 04:00:40 +00:00
|
|
|
def __init__(self, exchange, pairlistmanager,
|
|
|
|
config: Dict[str, Any], pairlistconfig: Dict[str, Any],
|
2019-11-09 14:04:04 +00:00
|
|
|
pairlist_pos: int) -> None:
|
|
|
|
super().__init__(exchange, pairlistmanager, config, pairlistconfig, pairlist_pos)
|
2019-10-30 14:59:52 +00:00
|
|
|
|
2019-11-19 05:34:54 +00:00
|
|
|
self._low_price_ratio = pairlistconfig.get('low_price_ratio', 0)
|
2019-11-09 05:55:16 +00:00
|
|
|
|
2019-11-09 06:05:17 +00:00
|
|
|
@property
|
|
|
|
def needstickers(self) -> bool:
|
|
|
|
"""
|
|
|
|
Boolean property defining if tickers are necessary.
|
|
|
|
If no Pairlist requries tickers, an empty List is passed
|
|
|
|
as tickers argument to filter_pairlist
|
|
|
|
"""
|
|
|
|
return True
|
|
|
|
|
2019-11-09 05:55:16 +00:00
|
|
|
def short_desc(self) -> str:
|
|
|
|
"""
|
|
|
|
Short whitelist method description - used for startup-messages
|
|
|
|
"""
|
2019-11-19 05:34:54 +00:00
|
|
|
return f"{self.name} - Filtering pairs priced below {self._low_price_ratio * 100}%."
|
2019-10-30 14:59:52 +00:00
|
|
|
|
2019-10-30 15:32:22 +00:00
|
|
|
def _validate_ticker_lowprice(self, ticker) -> bool:
|
2019-10-30 14:59:52 +00:00
|
|
|
"""
|
2019-11-19 05:41:05 +00:00
|
|
|
Check if if one price-step (pip) is > than a certain barrier.
|
2019-10-30 14:59:52 +00:00
|
|
|
:param ticker: ticker dict as returned from ccxt.load_markets()
|
|
|
|
:param precision: Precision
|
|
|
|
:return: True if the pair can stay, false if it should be removed
|
|
|
|
"""
|
2019-11-09 05:55:16 +00:00
|
|
|
precision = self._exchange.markets[ticker['symbol']]['precision']['price']
|
2019-10-30 14:59:52 +00:00
|
|
|
|
|
|
|
compare = ticker['last'] + 1 / pow(10, precision)
|
|
|
|
changeperc = (compare - ticker['last']) / ticker['last']
|
2019-11-19 05:34:54 +00:00
|
|
|
if changeperc > self._low_price_ratio:
|
2019-10-30 14:59:52 +00:00
|
|
|
logger.info(f"Removed {ticker['symbol']} from whitelist, "
|
|
|
|
f"because 1 unit is {changeperc * 100:.3f}%")
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2019-11-09 12:40:36 +00:00
|
|
|
def filter_pairlist(self, pairlist: List[str], tickers: Dict) -> List[str]:
|
2019-11-09 05:55:16 +00:00
|
|
|
|
2019-10-30 14:59:52 +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
|
|
|
|
:param tickers: Tickers (from exchange.get_tickers()). May be cached.
|
|
|
|
:return: new whitelist
|
2019-10-30 14:59:52 +00:00
|
|
|
"""
|
|
|
|
# Copy list since we're modifying this list
|
|
|
|
for p in deepcopy(pairlist):
|
2019-11-09 12:40:36 +00:00
|
|
|
ticker = tickers.get(p)
|
|
|
|
if not ticker:
|
|
|
|
pairlist.remove(p)
|
2019-10-30 14:59:52 +00:00
|
|
|
|
|
|
|
# Filter out assets which would not allow setting a stoploss
|
2019-11-19 05:34:54 +00:00
|
|
|
if self._low_price_ratio and not self._validate_ticker_lowprice(ticker):
|
2019-10-30 14:59:52 +00:00
|
|
|
pairlist.remove(p)
|
|
|
|
|
|
|
|
return pairlist
|