From d52169930563e2ec9bb3eefa092a4c1d70360d15 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 15 Aug 2024 08:07:45 +0200 Subject: [PATCH] refactor: type fetch_positions response --- freqtrade/exchange/exchange.py | 13 ++++++++++--- freqtrade/exchange/types.py | 10 ++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index a7fe0be64..9e58acc27 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -88,7 +88,14 @@ from freqtrade.exchange.exchange_utils_timeframe import ( timeframe_to_seconds, ) from freqtrade.exchange.exchange_ws import ExchangeWS -from freqtrade.exchange.types import CcxtBalances, OHLCVResponse, OrderBook, Ticker, Tickers +from freqtrade.exchange.types import ( + CcxtBalances, + CcxtPosition, + OHLCVResponse, + OrderBook, + Ticker, + Tickers, +) from freqtrade.misc import ( chunks, deep_merge_dicts, @@ -1683,7 +1690,7 @@ class Exchange: raise OperationalException(e) from e @retrier - def fetch_positions(self, pair: Optional[str] = None) -> List[Dict]: + def fetch_positions(self, pair: Optional[str] = None) -> List[CcxtPosition]: """ Fetch positions from the exchange. If no pair is given, all positions are returned. @@ -1695,7 +1702,7 @@ class Exchange: symbols = [] if pair: symbols.append(pair) - positions: List[Dict] = self._api.fetch_positions(symbols) + positions: List[CcxtPosition] = self._api.fetch_positions(symbols) self._log_exchange_response("fetch_positions", positions) return positions except ccxt.DDoSProtection as e: diff --git a/freqtrade/exchange/types.py b/freqtrade/exchange/types.py index 357b3a40f..2a9ae1078 100644 --- a/freqtrade/exchange/types.py +++ b/freqtrade/exchange/types.py @@ -37,5 +37,15 @@ class CcxtBalance(TypedDict): CcxtBalances = Dict[str, CcxtBalance] +class CcxtPosition(TypedDict): + symbol: str + side: str + contracts: float + leverage: float + collateral: Optional[float] + initialMargin: Optional[float] + liquidationPrice: Optional[float] + + # pair, timeframe, candleType, OHLCV, drop last?, OHLCVResponse = Tuple[str, str, CandleType, List, bool]