stable/freqtrade/pairlist/PriceFilter.py

56 lines
2.0 KiB
Python
Raw Normal View History

2020-05-17 11:26:21 +00:00
"""
Price pair list filter
"""
2019-10-30 14:59:52 +00:00
import logging
2020-05-20 10:27:07 +00:00
from typing import Any, Dict
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
2020-05-17 11:26:21 +00:00
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],
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)
self._enabled = self._low_price_ratio != 0
2019-11-09 05:55:16 +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
2020-05-20 10:27:07 +00:00
def _validate_pair(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()
:return: True if the pair can stay, false if it should be removed
"""
if ticker['last'] is None:
self.log_on_refresh(logger.info,
2020-04-24 05:57:43 +00:00
f"Removed {ticker['symbol']} from whitelist, because "
"ticker['last'] is empty (Usually no trade in the last 24h).")
return False
2020-05-15 01:05:31 +00:00
compare = self._exchange.price_get_one_pip(ticker['symbol'], ticker['last'])
changeperc = compare / ticker['last']
2019-11-19 05:34:54 +00:00
if changeperc > self._low_price_ratio:
2020-04-14 18:21:10 +00:00
self.log_on_refresh(logger.info, f"Removed {ticker['symbol']} from whitelist, "
f"because 1 unit is {changeperc * 100:.3f}%")
2019-10-30 14:59:52 +00:00
return False
return True