mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
Improve type safety, refactor volatilityfilter
This commit is contained in:
parent
817ad64402
commit
e80ad309f1
|
@ -95,7 +95,7 @@ class VolatilityFilter(IPairList):
|
||||||
"sort_direction": {
|
"sort_direction": {
|
||||||
"type": "option",
|
"type": "option",
|
||||||
"default": None,
|
"default": None,
|
||||||
"options": [None, "asc", "desc"],
|
"options": ["", "asc", "desc"],
|
||||||
"description": "Sort pairlist",
|
"description": "Sort pairlist",
|
||||||
"help": "Sort Pairlist ascending or descending by volatility.",
|
"help": "Sort Pairlist ascending or descending by volatility.",
|
||||||
},
|
},
|
||||||
|
@ -125,19 +125,19 @@ class VolatilityFilter(IPairList):
|
||||||
if volatility_avg is not None:
|
if volatility_avg is not None:
|
||||||
if self._validate_pair_loc(p, volatility_avg):
|
if self._validate_pair_loc(p, volatility_avg):
|
||||||
resulting_pairlist.append(p)
|
resulting_pairlist.append(p)
|
||||||
|
volatilitys[p] = (
|
||||||
|
volatility_avg if volatility_avg and not np.isnan(volatility_avg) else 0
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self.log_once(f"Removed {p} from whitelist, no candles found.", logger.info)
|
self.log_once(f"Removed {p} from whitelist, no candles found.", logger.info)
|
||||||
|
|
||||||
if self._sort_direction:
|
|
||||||
volatilitys[p] = volatility_avg if not np.isnan(volatility_avg) else 0
|
|
||||||
|
|
||||||
if self._sort_direction:
|
if self._sort_direction:
|
||||||
resulting_pairlist = sorted(resulting_pairlist,
|
resulting_pairlist = sorted(resulting_pairlist,
|
||||||
key=lambda p: volatilitys[p],
|
key=lambda p: volatilitys[p],
|
||||||
reverse=self._sort_direction == 'desc')
|
reverse=self._sort_direction == 'desc')
|
||||||
return resulting_pairlist
|
return resulting_pairlist
|
||||||
|
|
||||||
def _calculate_volatility(self, pair: str, daily_candles: DataFrame) -> float:
|
def _calculate_volatility(self, pair: str, daily_candles: DataFrame) -> Optional[float]:
|
||||||
# Check symbol in cache
|
# Check symbol in cache
|
||||||
if (volatility_avg := self._pair_cache.get(pair, None)) is not None:
|
if (volatility_avg := self._pair_cache.get(pair, None)) is not None:
|
||||||
return volatility_avg
|
return volatility_avg
|
||||||
|
|
|
@ -93,7 +93,7 @@ class RangeStabilityFilter(IPairList):
|
||||||
"sort_direction": {
|
"sort_direction": {
|
||||||
"type": "option",
|
"type": "option",
|
||||||
"default": None,
|
"default": None,
|
||||||
"options": [None, "asc", "desc"],
|
"options": ["", "asc", "desc"],
|
||||||
"description": "Sort pairlist",
|
"description": "Sort pairlist",
|
||||||
"help": "Sort Pairlist ascending or descending by rate of change.",
|
"help": "Sort Pairlist ascending or descending by rate of change.",
|
||||||
},
|
},
|
||||||
|
@ -134,7 +134,7 @@ class RangeStabilityFilter(IPairList):
|
||||||
reverse=self._sort_direction == 'desc')
|
reverse=self._sort_direction == 'desc')
|
||||||
return resulting_pairlist
|
return resulting_pairlist
|
||||||
|
|
||||||
def _calculate_rate_of_change(self, pair: str, daily_candles: DataFrame) -> float:
|
def _calculate_rate_of_change(self, pair: str, daily_candles: DataFrame) -> Optional[float]:
|
||||||
# Check symbol in cache
|
# Check symbol in cache
|
||||||
if (pct_change := self._pair_cache.get(pair, None)) is not None:
|
if (pct_change := self._pair_cache.get(pair, None)) is not None:
|
||||||
return pct_change
|
return pct_change
|
||||||
|
|
Loading…
Reference in New Issue
Block a user