From 964d437c7a029db8c59b65e441515485d65550bc Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 4 Sep 2024 07:15:17 +0200 Subject: [PATCH] chore: type _ft_has --- freqtrade/exchange/binance.py | 6 ++-- freqtrade/exchange/bingx.py | 4 +-- freqtrade/exchange/bitmart.py | 4 +-- freqtrade/exchange/bitvavo.py | 4 +-- freqtrade/exchange/bybit.py | 5 +-- freqtrade/exchange/coinbasepro.py | 4 +-- freqtrade/exchange/cryptocom.py | 4 +-- freqtrade/exchange/exchange.py | 10 +++--- freqtrade/exchange/exchange_types.py | 47 ++++++++++++++++++++++++++++ freqtrade/exchange/gate.py | 5 +-- freqtrade/exchange/hitbtc.py | 4 +-- freqtrade/exchange/htx.py | 3 +- freqtrade/exchange/hyperliquid.py | 3 +- freqtrade/exchange/idex.py | 4 +-- freqtrade/exchange/kraken.py | 4 +-- freqtrade/exchange/kucoin.py | 3 +- freqtrade/exchange/okx.py | 5 +-- 17 files changed, 87 insertions(+), 32 deletions(-) diff --git a/freqtrade/exchange/binance.py b/freqtrade/exchange/binance.py index f20920df6..d2e74f9eb 100644 --- a/freqtrade/exchange/binance.py +++ b/freqtrade/exchange/binance.py @@ -11,7 +11,7 @@ from freqtrade.enums import CandleType, MarginMode, PriceType, TradingMode from freqtrade.exceptions import DDosProtection, OperationalException, TemporaryError from freqtrade.exchange import Exchange from freqtrade.exchange.common import retrier -from freqtrade.exchange.exchange_types import OHLCVResponse, Tickers +from freqtrade.exchange.exchange_types import FtHas, OHLCVResponse, Tickers from freqtrade.misc import deep_merge_dicts, json_load @@ -19,7 +19,7 @@ logger = logging.getLogger(__name__) class Binance(Exchange): - _ft_has: Dict = { + _ft_has: FtHas = { "stoploss_on_exchange": True, "stop_price_param": "stopPrice", "stop_price_prop": "stopPrice", @@ -32,7 +32,7 @@ class Binance(Exchange): "l2_limit_range": [5, 10, 20, 50, 100, 500, 1000], "ws_enabled": True, } - _ft_has_futures: Dict = { + _ft_has_futures: FtHas = { "stoploss_order_types": {"limit": "stop", "market": "stop_market"}, "order_time_in_force": ["GTC", "FOK", "IOC"], "tickers_have_price": False, diff --git a/freqtrade/exchange/bingx.py b/freqtrade/exchange/bingx.py index 4dcff8a21..1caf7a737 100644 --- a/freqtrade/exchange/bingx.py +++ b/freqtrade/exchange/bingx.py @@ -1,9 +1,9 @@ """Bingx exchange subclass""" import logging -from typing import Dict from freqtrade.exchange import Exchange +from freqtrade.exchange.exchange_types import FtHas logger = logging.getLogger(__name__) @@ -15,7 +15,7 @@ class Bingx(Exchange): with this exchange. """ - _ft_has: Dict = { + _ft_has: FtHas = { "ohlcv_candle_limit": 1000, "stoploss_on_exchange": True, "stoploss_order_types": {"limit": "limit", "market": "market"}, diff --git a/freqtrade/exchange/bitmart.py b/freqtrade/exchange/bitmart.py index ab509c786..8fed36bec 100644 --- a/freqtrade/exchange/bitmart.py +++ b/freqtrade/exchange/bitmart.py @@ -1,9 +1,9 @@ """Bitmart exchange subclass""" import logging -from typing import Dict from freqtrade.exchange import Exchange +from freqtrade.exchange.exchange_types import FtHas logger = logging.getLogger(__name__) @@ -15,7 +15,7 @@ class Bitmart(Exchange): with this exchange. """ - _ft_has: Dict = { + _ft_has: FtHas = { "stoploss_on_exchange": False, # Bitmart API does not support stoploss orders "ohlcv_candle_limit": 200, "trades_has_history": False, # Endpoint doesn't seem to support pagination diff --git a/freqtrade/exchange/bitvavo.py b/freqtrade/exchange/bitvavo.py index ff0c0e37f..fdbb8a7d4 100644 --- a/freqtrade/exchange/bitvavo.py +++ b/freqtrade/exchange/bitvavo.py @@ -1,11 +1,11 @@ """Bitvavo exchange subclass.""" import logging -from typing import Dict from ccxt import DECIMAL_PLACES from freqtrade.exchange import Exchange +from freqtrade.exchange.exchange_types import FtHas logger = logging.getLogger(__name__) @@ -21,7 +21,7 @@ class Bitvavo(Exchange): may still not work as expected. """ - _ft_has: Dict = { + _ft_has: FtHas = { "ohlcv_candle_limit": 1440, } diff --git a/freqtrade/exchange/bybit.py b/freqtrade/exchange/bybit.py index ce9c38fff..52cf37d31 100644 --- a/freqtrade/exchange/bybit.py +++ b/freqtrade/exchange/bybit.py @@ -11,6 +11,7 @@ from freqtrade.enums import CandleType, MarginMode, PriceType, TradingMode from freqtrade.exceptions import DDosProtection, ExchangeError, OperationalException, TemporaryError from freqtrade.exchange import Exchange from freqtrade.exchange.common import retrier +from freqtrade.exchange.exchange_types import FtHas from freqtrade.util.datetime_helpers import dt_now, dt_ts @@ -29,14 +30,14 @@ class Bybit(Exchange): unified_account = False - _ft_has: Dict = { + _ft_has: FtHas = { "ohlcv_candle_limit": 1000, "ohlcv_has_history": True, "order_time_in_force": ["GTC", "FOK", "IOC", "PO"], "ws_enabled": True, "trades_has_history": False, # Endpoint doesn't support pagination } - _ft_has_futures: Dict = { + _ft_has_futures: FtHas = { "ohlcv_has_history": True, "mark_ohlcv_timeframe": "4h", "funding_fee_timeframe": "8h", diff --git a/freqtrade/exchange/coinbasepro.py b/freqtrade/exchange/coinbasepro.py index e234002ad..cc561e8ce 100644 --- a/freqtrade/exchange/coinbasepro.py +++ b/freqtrade/exchange/coinbasepro.py @@ -1,9 +1,9 @@ """CoinbasePro exchange subclass""" import logging -from typing import Dict from freqtrade.exchange import Exchange +from freqtrade.exchange.exchange_types import FtHas logger = logging.getLogger(__name__) @@ -19,6 +19,6 @@ class Coinbasepro(Exchange): may still not work as expected. """ - _ft_has: Dict = { + _ft_has: FtHas = { "ohlcv_candle_limit": 300, } diff --git a/freqtrade/exchange/cryptocom.py b/freqtrade/exchange/cryptocom.py index 56b007b07..4782c5a49 100644 --- a/freqtrade/exchange/cryptocom.py +++ b/freqtrade/exchange/cryptocom.py @@ -1,9 +1,9 @@ """Crypto.com exchange subclass""" import logging -from typing import Dict from freqtrade.exchange import Exchange +from freqtrade.exchange.exchange_types import FtHas logger = logging.getLogger(__name__) @@ -14,6 +14,6 @@ class Cryptocom(Exchange): Contains adjustments needed for Freqtrade to work with this exchange. """ - _ft_has: Dict = { + _ft_has: FtHas = { "ohlcv_candle_limit": 300, } diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index df1971999..cb1c1a49a 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -70,6 +70,7 @@ from freqtrade.exchange.common import ( from freqtrade.exchange.exchange_types import ( CcxtBalances, CcxtPosition, + FtHas, OHLCVResponse, OrderBook, Ticker, @@ -122,10 +123,11 @@ class Exchange: # Dict to specify which options each exchange implements # This defines defaults, which can be selectively overridden by subclasses using _ft_has # or by specifying them in the configuration. - _ft_has_default: Dict = { + _ft_has_default: FtHas = { "stoploss_on_exchange": False, "stop_price_param": "stopLossPrice", # Used for stoploss_on_exchange request "stop_price_prop": "stopLossPrice", # Used for stoploss_on_exchange response parsing + "stoploss_order_types": {}, "order_time_in_force": ["GTC"], "ohlcv_params": {}, "ohlcv_candle_limit": 500, @@ -156,8 +158,8 @@ class Exchange: # Expected to be in the format {"fetchOHLCV": True} or {"fetchOHLCV": False} "ws_enabled": False, # Set to true for exchanges with tested websocket support } - _ft_has: Dict = {} - _ft_has_futures: Dict = {} + _ft_has: FtHas = {} + _ft_has_futures: FtHas = {} _supported_trading_mode_margin_pairs: List[Tuple[TradingMode, MarginMode]] = [ # TradingMode.SPOT always supported and not required in this list @@ -466,7 +468,7 @@ class Exchange: """ return int( self._ft_has.get("ohlcv_candle_limit_per_timeframe", {}).get( - timeframe, self._ft_has.get("ohlcv_candle_limit") + timeframe, str(self._ft_has.get("ohlcv_candle_limit")) ) ) diff --git a/freqtrade/exchange/exchange_types.py b/freqtrade/exchange/exchange_types.py index 2a9ae1078..ef3ed274b 100644 --- a/freqtrade/exchange/exchange_types.py +++ b/freqtrade/exchange/exchange_types.py @@ -3,6 +3,53 @@ from typing import Dict, List, Optional, Tuple, TypedDict from freqtrade.enums import CandleType +class FtHas(TypedDict, total=False): + order_time_in_force: List[str] + exchange_has_overrides: Dict[str, bool] + marketOrderRequiresPrice: bool + + # Stoploss on exchange + stoploss_on_exchange: bool + stop_price_param: str + stop_price_prop: str + stop_price_type_field: str + stop_price_type_value_mapping: Dict + stoploss_order_types: Dict[str, str] + # ohlcv + ohlcv_params: Dict + ohlcv_candle_limit: int + ohlcv_has_history: bool + ohlcv_partial_candle: bool + ohlcv_require_since: bool + ohlcv_volume_currency: str + ohlcv_candle_limit_per_timeframe: Dict[str, int] + # Tickers + tickers_have_quoteVolume: bool + tickers_have_percentage: bool + tickers_have_bid_ask: bool + tickers_have_price: bool + # Trades + trades_limit: int + trades_pagination: str + trades_pagination_arg: str + trades_has_history: bool + trades_pagination_overlap: bool + # Orderbook + l2_limit_range: Optional[List[int]] + l2_limit_range_required: bool + # Futures + ccxt_futures_name: str # usually swap + mark_ohlcv_price: str + mark_ohlcv_timeframe: str + funding_fee_timeframe: str + floor_leverage: bool + needs_trading_fees: bool + order_props_in_contracts: List[str] + + # Websocket control + ws_enabled: bool + + class Ticker(TypedDict): symbol: str ask: Optional[float] diff --git a/freqtrade/exchange/gate.py b/freqtrade/exchange/gate.py index 9ed5a7366..4096a851a 100644 --- a/freqtrade/exchange/gate.py +++ b/freqtrade/exchange/gate.py @@ -7,6 +7,7 @@ from typing import Any, Dict, List, Optional, Tuple from freqtrade.constants import BuySell from freqtrade.enums import MarginMode, PriceType, TradingMode from freqtrade.exchange import Exchange +from freqtrade.exchange.exchange_types import FtHas from freqtrade.misc import safe_value_fallback2 @@ -23,7 +24,7 @@ class Gate(Exchange): may still not work as expected. """ - _ft_has: Dict = { + _ft_has: FtHas = { "ohlcv_candle_limit": 1000, "order_time_in_force": ["GTC", "IOC"], "stoploss_on_exchange": True, @@ -34,7 +35,7 @@ class Gate(Exchange): "trades_has_history": False, # Endpoint would support this - but ccxt doesn't. } - _ft_has_futures: Dict = { + _ft_has_futures: FtHas = { "needs_trading_fees": True, "marketOrderRequiresPrice": False, "stop_price_type_field": "price_type", diff --git a/freqtrade/exchange/hitbtc.py b/freqtrade/exchange/hitbtc.py index bc4c7aa81..d37c7f12e 100644 --- a/freqtrade/exchange/hitbtc.py +++ b/freqtrade/exchange/hitbtc.py @@ -1,7 +1,7 @@ import logging -from typing import Dict from freqtrade.exchange import Exchange +from freqtrade.exchange.exchange_types import FtHas logger = logging.getLogger(__name__) @@ -17,6 +17,6 @@ class Hitbtc(Exchange): may still not work as expected. """ - _ft_has: Dict = { + _ft_has: FtHas = { "ohlcv_candle_limit": 1000, } diff --git a/freqtrade/exchange/htx.py b/freqtrade/exchange/htx.py index fa26a5ffd..9bd931f51 100644 --- a/freqtrade/exchange/htx.py +++ b/freqtrade/exchange/htx.py @@ -5,6 +5,7 @@ from typing import Dict from freqtrade.constants import BuySell from freqtrade.exchange import Exchange +from freqtrade.exchange.exchange_types import FtHas logger = logging.getLogger(__name__) @@ -16,7 +17,7 @@ class Htx(Exchange): with this exchange. """ - _ft_has: Dict = { + _ft_has: FtHas = { "stoploss_on_exchange": True, "stop_price_param": "stopPrice", "stop_price_prop": "stopPrice", diff --git a/freqtrade/exchange/hyperliquid.py b/freqtrade/exchange/hyperliquid.py index f8835d1dc..69905c416 100644 --- a/freqtrade/exchange/hyperliquid.py +++ b/freqtrade/exchange/hyperliquid.py @@ -7,6 +7,7 @@ from ccxt import SIGNIFICANT_DIGITS from freqtrade.enums import TradingMode from freqtrade.exchange import Exchange +from freqtrade.exchange.exchange_types import FtHas logger = logging.getLogger(__name__) @@ -17,7 +18,7 @@ class Hyperliquid(Exchange): Contains adjustments needed for Freqtrade to work with this exchange. """ - _ft_has: Dict = { + _ft_has: FtHas = { # Only the most recent 5000 candles are available according to the # exchange's API documentation. "ohlcv_has_history": False, diff --git a/freqtrade/exchange/idex.py b/freqtrade/exchange/idex.py index b3bf12110..9c750f64d 100644 --- a/freqtrade/exchange/idex.py +++ b/freqtrade/exchange/idex.py @@ -1,9 +1,9 @@ """Idex exchange subclass""" import logging -from typing import Dict from freqtrade.exchange import Exchange +from freqtrade.exchange.exchange_types import FtHas logger = logging.getLogger(__name__) @@ -15,6 +15,6 @@ class Idex(Exchange): with this exchange. """ - _ft_has: Dict = { + _ft_has: FtHas = { "ohlcv_candle_limit": 1000, } diff --git a/freqtrade/exchange/kraken.py b/freqtrade/exchange/kraken.py index b0734cb6c..7f3346cfe 100644 --- a/freqtrade/exchange/kraken.py +++ b/freqtrade/exchange/kraken.py @@ -12,7 +12,7 @@ from freqtrade.enums import MarginMode, TradingMode from freqtrade.exceptions import DDosProtection, OperationalException, TemporaryError from freqtrade.exchange import Exchange from freqtrade.exchange.common import retrier -from freqtrade.exchange.exchange_types import CcxtBalances, Tickers +from freqtrade.exchange.exchange_types import CcxtBalances, FtHas, Tickers logger = logging.getLogger(__name__) @@ -20,7 +20,7 @@ logger = logging.getLogger(__name__) class Kraken(Exchange): _params: Dict = {"trading_agreement": "agree"} - _ft_has: Dict = { + _ft_has: FtHas = { "stoploss_on_exchange": True, "stop_price_param": "stopLossPrice", "stop_price_prop": "stopLossPrice", diff --git a/freqtrade/exchange/kucoin.py b/freqtrade/exchange/kucoin.py index 343904276..bbf120d40 100644 --- a/freqtrade/exchange/kucoin.py +++ b/freqtrade/exchange/kucoin.py @@ -5,6 +5,7 @@ from typing import Dict from freqtrade.constants import BuySell from freqtrade.exchange import Exchange +from freqtrade.exchange.exchange_types import FtHas logger = logging.getLogger(__name__) @@ -20,7 +21,7 @@ class Kucoin(Exchange): may still not work as expected. """ - _ft_has: Dict = { + _ft_has: FtHas = { "stoploss_on_exchange": True, "stop_price_param": "stopPrice", "stop_price_prop": "stopPrice", diff --git a/freqtrade/exchange/okx.py b/freqtrade/exchange/okx.py index 248028973..8a781982a 100644 --- a/freqtrade/exchange/okx.py +++ b/freqtrade/exchange/okx.py @@ -14,6 +14,7 @@ from freqtrade.exceptions import ( ) from freqtrade.exchange import Exchange, date_minus_candles from freqtrade.exchange.common import retrier +from freqtrade.exchange.exchange_types import FtHas from freqtrade.misc import safe_value_fallback2 from freqtrade.util import dt_now, dt_ts @@ -27,7 +28,7 @@ class Okx(Exchange): Contains adjustments needed for Freqtrade to work with this exchange. """ - _ft_has: Dict = { + _ft_has: FtHas = { "ohlcv_candle_limit": 100, # Warning, special case with data prior to X months "mark_ohlcv_timeframe": "4h", "funding_fee_timeframe": "8h", @@ -36,7 +37,7 @@ class Okx(Exchange): "trades_has_history": False, # Endpoint doesn't have a "since" parameter "ws_enabled": True, } - _ft_has_futures: Dict = { + _ft_has_futures: FtHas = { "tickers_have_quoteVolume": False, "stop_price_type_field": "slTriggerPxType", "stop_price_type_value_mapping": {