From 52e9528361b73bced2f34c77d7bbbebaa1b7fa23 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 11 Oct 2022 19:33:07 +0000 Subject: [PATCH] Improve ticker type --- freqtrade/exchange/binance.py | 3 ++- freqtrade/exchange/types.py | 15 +++++++++++++-- freqtrade/plugins/pairlist/PriceFilter.py | 6 +++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/freqtrade/exchange/binance.py b/freqtrade/exchange/binance.py index a0d4b2d82..6d818bab9 100644 --- a/freqtrade/exchange/binance.py +++ b/freqtrade/exchange/binance.py @@ -11,6 +11,7 @@ from freqtrade.enums import CandleType, MarginMode, TradingMode from freqtrade.exceptions import DDosProtection, OperationalException, TemporaryError from freqtrade.exchange import Exchange from freqtrade.exchange.common import retrier +from freqtrade.exchange.types import Tickers from freqtrade.misc import deep_merge_dicts, json_load @@ -59,7 +60,7 @@ class Binance(Exchange): ) )) - def get_tickers(self, symbols: Optional[List[str]] = None, cached: bool = False) -> Dict: + def get_tickers(self, symbols: Optional[List[str]] = None, cached: bool = False) -> Tickers: tickers = super().get_tickers(symbols=symbols, cached=cached) if self.trading_mode == TradingMode.FUTURES: # Binance's future result has no bid/ask values. diff --git a/freqtrade/exchange/types.py b/freqtrade/exchange/types.py index 6504381dc..a60b454d4 100644 --- a/freqtrade/exchange/types.py +++ b/freqtrade/exchange/types.py @@ -1,5 +1,16 @@ -from typing import Any, Dict +from typing import Dict, Optional, TypedDict + + +class Ticker(TypedDict): + symbol: str + ask: Optional[float] + askVolume: Optional[float] + bid: Optional[float] + bidVolume: Optional[float] + last: Optional[float] + quoteVolume: Optional[float] + baseVolume: Optional[float] + # Several more - only listing required. -Ticker = Dict[str, Any] Tickers = Dict[str, Ticker] diff --git a/freqtrade/plugins/pairlist/PriceFilter.py b/freqtrade/plugins/pairlist/PriceFilter.py index da41e9239..4d23de792 100644 --- a/freqtrade/plugins/pairlist/PriceFilter.py +++ b/freqtrade/plugins/pairlist/PriceFilter.py @@ -72,13 +72,13 @@ class PriceFilter(IPairList): :param ticker: ticker dict as returned from ccxt.fetch_ticker :return: True if the pair can stay, false if it should be removed """ - if not ticker or ticker.get('last', None) is None or ticker.get('last') == 0: + if ticker and 'last' in ticker and ticker['last'] is not None and ticker.get('last') != 0: + price: float = ticker['last'] + else: self.log_once(f"Removed {pair} from whitelist, because " "ticker['last'] is empty (Usually no trade in the last 24h).", logger.info) return False - else: - price: float = ticker['last'] # Perform low_price_ratio check. if self._low_price_ratio != 0: