stable/freqtrade/pairlist/PrecisionFilter.py

68 lines
2.4 KiB
Python
Raw Normal View History

2020-05-17 11:26:21 +00:00
"""
Precision 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
from freqtrade.exceptions import OperationalException
2020-09-28 17:39:41 +00:00
from freqtrade.pairlist.IPairList import IPairList
2020-05-17 11:26:21 +00:00
2019-10-30 14:59:52 +00:00
logger = logging.getLogger(__name__)
2019-11-09 05:55:16 +00:00
class PrecisionFilter(IPairList):
2019-10-30 14:59:52 +00:00
2020-05-15 01:17:23 +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)
if 'stoploss' not in self._config:
raise OperationalException(
'PrecisionFilter can only work with stoploss defined. Please add the '
'stoploss key to your configuration (overwrites eventual strategy settings).')
self._stoploss = self._config['stoploss']
self._enabled = self._stoploss != 0
2020-05-17 08:11:49 +00:00
# Precalculate sanitized stoploss value to avoid recalculation for every pair
self._stoploss = 1 - abs(self._stoploss)
2020-05-15 01:17:23 +00:00
@property
def needstickers(self) -> bool:
"""
Boolean property defining if tickers are necessary.
2020-11-24 19:24:51 +00:00
If no Pairlist requires tickers, an empty Dict 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
"""
return f"{self.name} - Filtering untradable pairs."
2019-10-30 14:59:52 +00:00
2020-05-20 10:27:07 +00:00
def _validate_pair(self, ticker: dict) -> bool:
2019-10-30 14:59:52 +00:00
"""
Check if pair has enough room to add a stoploss to avoid "unsellable" buys of very
low value pairs.
:param ticker: ticker dict as returned from ccxt.load_markets()
2020-05-15 02:14:06 +00:00
:return: True if the pair can stay, False if it should be removed
2019-10-30 14:59:52 +00:00
"""
2020-05-20 10:27:07 +00:00
stop_price = ticker['ask'] * self._stoploss
2020-05-15 01:24:18 +00:00
2019-10-30 14:59:52 +00:00
# Adjust stop-prices to precision
sp = self._exchange.price_to_precision(ticker["symbol"], stop_price)
2020-05-15 01:24:18 +00:00
stop_gap_price = self._exchange.price_to_precision(ticker["symbol"], stop_price * 0.99)
2019-10-30 14:59:52 +00:00
logger.debug(f"{ticker['symbol']} - {sp} : {stop_gap_price}")
2020-05-15 01:24:18 +00:00
2019-10-30 14:59:52 +00:00
if sp <= stop_gap_price:
self.log_on_refresh(logger.info,
f"Removed {ticker['symbol']} from whitelist, "
f"because stop price {sp} would be <= stop limit {stop_gap_price}")
2019-10-30 14:59:52 +00:00
return False
2020-05-15 01:24:18 +00:00
2019-10-30 14:59:52 +00:00
return True