refactor: improve live positions update

This commit is contained in:
Matthias 2024-08-15 15:44:59 +02:00
parent 2ffe938206
commit 756fef53f9

View File

@ -149,7 +149,7 @@ class Wallets:
del self._wallets[currency] del self._wallets[currency]
positions = self._exchange.fetch_positions() positions = self._exchange.fetch_positions()
self._positions = {} _parsed_positions = {}
for position in positions: for position in positions:
symbol = position["symbol"] symbol = position["symbol"]
if position["side"] is None or position["collateral"] == 0.0: if position["side"] is None or position["collateral"] == 0.0:
@ -158,13 +158,14 @@ class Wallets:
size = self._exchange._contracts_to_amount(symbol, position["contracts"]) size = self._exchange._contracts_to_amount(symbol, position["contracts"])
collateral = safe_value_fallback(position, "collateral", "initialMargin", 0.0) collateral = safe_value_fallback(position, "collateral", "initialMargin", 0.0)
leverage = position["leverage"] leverage = position["leverage"]
self._positions[symbol] = PositionWallet( _parsed_positions[symbol] = PositionWallet(
symbol, symbol,
position=size, position=size,
leverage=leverage, leverage=leverage,
collateral=collateral, collateral=collateral,
side=position["side"], side=position["side"],
) )
self._positions = _parsed_positions
def update(self, require_update: bool = True) -> None: def update(self, require_update: bool = True) -> None:
""" """