mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-11-29 08:33:07 +00:00
chore: improve typing for balance endpoint
This commit is contained in:
@@ -88,7 +88,7 @@ from freqtrade.exchange.exchange_utils_timeframe import (
|
|||||||
timeframe_to_seconds,
|
timeframe_to_seconds,
|
||||||
)
|
)
|
||||||
from freqtrade.exchange.exchange_ws import ExchangeWS
|
from freqtrade.exchange.exchange_ws import ExchangeWS
|
||||||
from freqtrade.exchange.types import OHLCVResponse, OrderBook, Ticker, Tickers
|
from freqtrade.exchange.types import CcxtBalances, OHLCVResponse, OrderBook, Ticker, Tickers
|
||||||
from freqtrade.misc import (
|
from freqtrade.misc import (
|
||||||
chunks,
|
chunks,
|
||||||
deep_merge_dicts,
|
deep_merge_dicts,
|
||||||
@@ -1663,7 +1663,7 @@ class Exchange:
|
|||||||
return order
|
return order
|
||||||
|
|
||||||
@retrier
|
@retrier
|
||||||
def get_balances(self) -> dict:
|
def get_balances(self) -> CcxtBalances:
|
||||||
try:
|
try:
|
||||||
balances = self._api.fetch_balance()
|
balances = self._api.fetch_balance()
|
||||||
# Remove additional info from ccxt results
|
# Remove additional info from ccxt results
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ from freqtrade.enums import MarginMode, TradingMode
|
|||||||
from freqtrade.exceptions import DDosProtection, OperationalException, TemporaryError
|
from freqtrade.exceptions import DDosProtection, OperationalException, TemporaryError
|
||||||
from freqtrade.exchange import Exchange
|
from freqtrade.exchange import Exchange
|
||||||
from freqtrade.exchange.common import retrier
|
from freqtrade.exchange.common import retrier
|
||||||
from freqtrade.exchange.types import Tickers
|
from freqtrade.exchange.types import CcxtBalances, Tickers
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -57,7 +57,7 @@ class Kraken(Exchange):
|
|||||||
return super().get_tickers(symbols=symbols, cached=cached)
|
return super().get_tickers(symbols=symbols, cached=cached)
|
||||||
|
|
||||||
@retrier
|
@retrier
|
||||||
def get_balances(self) -> dict:
|
def get_balances(self) -> CcxtBalances:
|
||||||
if self._config["dry_run"]:
|
if self._config["dry_run"]:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,14 @@ class OrderBook(TypedDict):
|
|||||||
nonce: Optional[int]
|
nonce: Optional[int]
|
||||||
|
|
||||||
|
|
||||||
|
class CcxtBalance(TypedDict):
|
||||||
|
free: float
|
||||||
|
used: float
|
||||||
|
total: float
|
||||||
|
|
||||||
|
|
||||||
|
CcxtBalances = Dict[str, CcxtBalance]
|
||||||
|
|
||||||
Tickers = Dict[str, Ticker]
|
Tickers = Dict[str, Ticker]
|
||||||
|
|
||||||
# pair, timeframe, candleType, OHLCV, drop last?,
|
# pair, timeframe, candleType, OHLCV, drop last?,
|
||||||
|
|||||||
@@ -139,9 +139,9 @@ class Wallets:
|
|||||||
if isinstance(balances[currency], dict):
|
if isinstance(balances[currency], dict):
|
||||||
self._wallets[currency] = Wallet(
|
self._wallets[currency] = Wallet(
|
||||||
currency,
|
currency,
|
||||||
balances[currency].get("free"),
|
balances[currency].get("free", 0),
|
||||||
balances[currency].get("used"),
|
balances[currency].get("used", 0),
|
||||||
balances[currency].get("total"),
|
balances[currency].get("total", 0),
|
||||||
)
|
)
|
||||||
# Remove currencies no longer in get_balances output
|
# Remove currencies no longer in get_balances output
|
||||||
for currency in deepcopy(self._wallets):
|
for currency in deepcopy(self._wallets):
|
||||||
|
|||||||
Reference in New Issue
Block a user