Simplify SpreadFilter
This commit is contained in:
parent
cbb2ce3708
commit
143e6f52af
@ -41,7 +41,7 @@ class PrecisionFilter(IPairList):
|
|||||||
:param ticker: ticker dict as returned from ccxt.load_markets()
|
:param ticker: ticker dict as returned from ccxt.load_markets()
|
||||||
:param stoploss: stoploss value as set in the configuration
|
:param stoploss: stoploss value as set in the configuration
|
||||||
(already cleaned to be 1 - stoploss)
|
(already cleaned to be 1 - stoploss)
|
||||||
:return: True if the pair can stay, false if it should be removed
|
:return: True if the pair can stay, False if it should be removed
|
||||||
"""
|
"""
|
||||||
stop_price = ticker['ask'] * stoploss
|
stop_price = ticker['ask'] * stoploss
|
||||||
|
|
||||||
@ -63,13 +63,12 @@ class PrecisionFilter(IPairList):
|
|||||||
"""
|
"""
|
||||||
Filters and sorts pairlists and assigns and returns them again.
|
Filters and sorts pairlists and assigns and returns them again.
|
||||||
"""
|
"""
|
||||||
# Copy list since we're modifying this list
|
if self._stoploss:
|
||||||
for p in deepcopy(pairlist):
|
# Copy list since we're modifying this list
|
||||||
ticker = tickers.get(p)
|
for p in deepcopy(pairlist):
|
||||||
# Filter out assets which would not allow setting a stoploss
|
ticker = tickers[p]
|
||||||
if not ticker or (self._stoploss
|
# Filter out assets which would not allow setting a stoploss
|
||||||
and not self._validate_precision_filter(ticker, self._stoploss)):
|
if not self._validate_precision_filter(ticker, self._stoploss):
|
||||||
pairlist.remove(p)
|
pairlist.remove(p)
|
||||||
continue
|
|
||||||
|
|
||||||
return pairlist
|
return pairlist
|
||||||
|
@ -31,8 +31,24 @@ class SpreadFilter(IPairList):
|
|||||||
return (f"{self.name} - Filtering pairs with ask/bid diff above "
|
return (f"{self.name} - Filtering pairs with ask/bid diff above "
|
||||||
f"{self._max_spread_ratio * 100}%.")
|
f"{self._max_spread_ratio * 100}%.")
|
||||||
|
|
||||||
def filter_pairlist(self, pairlist: List[str], tickers: Dict) -> List[str]:
|
def _validate_spread(self, ticker: dict) -> bool:
|
||||||
|
"""
|
||||||
|
Validate spread for the ticker
|
||||||
|
:param ticker: ticker dict as returned from ccxt.load_markets()
|
||||||
|
:return: True if the pair can stay, False if it should be removed
|
||||||
|
"""
|
||||||
|
if 'bid' in ticker and 'ask' in ticker:
|
||||||
|
spread = 1 - ticker['bid'] / ticker['ask']
|
||||||
|
if spread > self._max_spread_ratio:
|
||||||
|
self.log_on_refresh(logger.info, f"Removed {ticker['symbol']} from whitelist, "
|
||||||
|
f"because spread {spread * 100:.3f}% >"
|
||||||
|
f"{self._max_spread_ratio * 100}%")
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def filter_pairlist(self, pairlist: List[str], tickers: Dict) -> List[str]:
|
||||||
"""
|
"""
|
||||||
Filters and sorts pairlist and returns the whitelist again.
|
Filters and sorts pairlist and returns the whitelist again.
|
||||||
Called on each bot iteration - please use internal caching if necessary
|
Called on each bot iteration - please use internal caching if necessary
|
||||||
@ -41,19 +57,10 @@ class SpreadFilter(IPairList):
|
|||||||
:return: new whitelist
|
:return: new whitelist
|
||||||
"""
|
"""
|
||||||
# Copy list since we're modifying this list
|
# Copy list since we're modifying this list
|
||||||
|
|
||||||
spread = None
|
|
||||||
for p in deepcopy(pairlist):
|
for p in deepcopy(pairlist):
|
||||||
ticker = tickers.get(p)
|
ticker = tickers[p]
|
||||||
assert ticker is not None
|
# Filter out assets
|
||||||
if 'bid' in ticker and 'ask' in ticker:
|
if not self._validate_spread(ticker):
|
||||||
spread = 1 - ticker['bid'] / ticker['ask']
|
|
||||||
if not ticker or spread > self._max_spread_ratio:
|
|
||||||
self.log_on_refresh(logger.info, f"Removed {ticker['symbol']} from whitelist, "
|
|
||||||
f"because spread {spread * 100:.3f}% >"
|
|
||||||
f"{self._max_spread_ratio * 100}%")
|
|
||||||
pairlist.remove(p)
|
|
||||||
else:
|
|
||||||
pairlist.remove(p)
|
pairlist.remove(p)
|
||||||
|
|
||||||
return pairlist
|
return pairlist
|
||||||
|
Loading…
Reference in New Issue
Block a user