Extract precision_filter to seperate function
This commit is contained in:
parent
4ff035537b
commit
d706571e6f
@ -56,6 +56,27 @@ class VolumePairList(IPairList):
|
|||||||
self._whitelist = self._gen_pair_whitelist(
|
self._whitelist = self._gen_pair_whitelist(
|
||||||
self._config['stake_currency'], self._sort_key)
|
self._config['stake_currency'], self._sort_key)
|
||||||
|
|
||||||
|
def _validate_precision_filter(self, ticker: dict, stoploss: float) -> bool:
|
||||||
|
"""
|
||||||
|
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()
|
||||||
|
:param stoploss: stoploss value as set in the configuration
|
||||||
|
(already cleaned to be guaranteed negative)
|
||||||
|
:return: True if the pair can stay, false if it should be removed
|
||||||
|
"""
|
||||||
|
stop_price = (self._freqtrade.get_target_bid(ticker["symbol"], ticker) * stoploss)
|
||||||
|
# Adjust stop-prices to precision
|
||||||
|
sp = self._freqtrade.exchange.symbol_price_prec(ticker["symbol"], stop_price)
|
||||||
|
stop_gap_price = self._freqtrade.exchange.symbol_price_prec(ticker["symbol"],
|
||||||
|
stop_price * 0.99)
|
||||||
|
logger.debug(f"{ticker['symbol']} - {sp} : {stop_gap_price}")
|
||||||
|
if sp <= stop_gap_price:
|
||||||
|
logger.info(f"Removed {ticker['symbol']} from whitelist, "
|
||||||
|
f"because stop price {sp} would be <= stop limit {stop_gap_price}")
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
@cached(TTLCache(maxsize=1, ttl=1800))
|
@cached(TTLCache(maxsize=1, ttl=1800))
|
||||||
def _gen_pair_whitelist(self, base_currency: str, key: str) -> List[str]:
|
def _gen_pair_whitelist(self, base_currency: str, key: str) -> List[str]:
|
||||||
"""
|
"""
|
||||||
@ -75,20 +96,15 @@ class VolumePairList(IPairList):
|
|||||||
valid_pairs = self._validate_whitelist([s['symbol'] for s in sorted_tickers])
|
valid_pairs = self._validate_whitelist([s['symbol'] for s in sorted_tickers])
|
||||||
valid_tickers = [t for t in sorted_tickers if t["symbol"] in valid_pairs]
|
valid_tickers = [t for t in sorted_tickers if t["symbol"] in valid_pairs]
|
||||||
|
|
||||||
if self._freqtrade.strategy.stoploss is not None and self._precision_filter:
|
stoploss = None
|
||||||
# Precalculate correct stoploss value
|
if self._freqtrade.strategy.stoploss is not None:
|
||||||
|
# Precalculate sanitized stoploss value to avoid recalculation for every pair
|
||||||
stoploss = 1 - abs(self._freqtrade.strategy.stoploss)
|
stoploss = 1 - abs(self._freqtrade.strategy.stoploss)
|
||||||
|
|
||||||
for i, t in enumerate(valid_tickers):
|
for t in valid_tickers:
|
||||||
stop_price = (self._freqtrade.get_target_bid(t["symbol"], t) * stoploss)
|
# Filter out assets which would not allow setting a stoploss
|
||||||
# Adjust stop-prices to precision
|
if (stoploss and self._precision_filter
|
||||||
sp = self._freqtrade.exchange.symbol_price_prec(t["symbol"], stop_price)
|
and not self._validate_precision_filter(t, stoploss)):
|
||||||
stop_gap_price = self._freqtrade.exchange.symbol_price_prec(t["symbol"],
|
|
||||||
stop_price * 0.99)
|
|
||||||
logger.debug(f"{t['symbol']} - {sp} : {stop_gap_price}")
|
|
||||||
if sp <= stop_gap_price:
|
|
||||||
logger.info(f"Removed {t['symbol']} from whitelist, "
|
|
||||||
f"because stop price {sp} would be <= stop limit {stop_gap_price}")
|
|
||||||
valid_tickers.remove(t)
|
valid_tickers.remove(t)
|
||||||
|
|
||||||
pairs = [s['symbol'] for s in valid_tickers]
|
pairs = [s['symbol'] for s in valid_tickers]
|
||||||
|
Loading…
Reference in New Issue
Block a user