Make stoploss an attribute

This commit is contained in:
hroff-1902 2020-05-15 04:17:23 +03:00
parent afa7a5846b
commit 794ed304b1

View File

@ -1,6 +1,6 @@
import logging
from copy import deepcopy
from typing import Dict, List
from typing import Any, Dict, List
from freqtrade.pairlist.IPairList import IPairList
@ -9,6 +9,16 @@ logger = logging.getLogger(__name__)
class PrecisionFilter(IPairList):
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)
self._stoploss = self._config.get('stoploss')
if self._stoploss is not None:
# Precalculate sanitized stoploss value to avoid recalculation for every pair
self._stoploss = 1 - abs(self._stoploss)
@property
def needstickers(self) -> bool:
"""
@ -49,15 +59,12 @@ class PrecisionFilter(IPairList):
"""
Filters and sorts pairlists and assigns and returns them again.
"""
stoploss = self._config.get('stoploss')
if stoploss is not None:
# Precalculate sanitized stoploss value to avoid recalculation for every pair
stoploss = 1 - abs(stoploss)
# Copy list since we're modifying this list
for p in deepcopy(pairlist):
ticker = tickers.get(p)
# Filter out assets which would not allow setting a stoploss
if not ticker or (stoploss and not self._validate_precision_filter(ticker, stoploss)):
if not ticker or (self._stoploss
and not self._validate_precision_filter(ticker, self._stoploss)):
pairlist.remove(p)
continue