chore: improve logic for live wallet update
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
"""Wallet"""
|
"""Wallet"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from copy import deepcopy
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import NamedTuple
|
from typing import NamedTuple
|
||||||
|
|
||||||
@@ -178,19 +177,16 @@ class Wallets:
|
|||||||
|
|
||||||
def _update_live(self) -> None:
|
def _update_live(self) -> None:
|
||||||
balances = self._exchange.get_balances()
|
balances = self._exchange.get_balances()
|
||||||
|
_wallets = {}
|
||||||
|
|
||||||
for currency in balances:
|
for currency in balances:
|
||||||
if isinstance(balances[currency], dict):
|
if isinstance(balances[currency], dict):
|
||||||
self._wallets[currency] = Wallet(
|
_wallets[currency] = Wallet(
|
||||||
currency,
|
currency,
|
||||||
balances[currency].get("free", 0),
|
balances[currency].get("free", 0),
|
||||||
balances[currency].get("used", 0),
|
balances[currency].get("used", 0),
|
||||||
balances[currency].get("total", 0),
|
balances[currency].get("total", 0),
|
||||||
)
|
)
|
||||||
# Remove currencies no longer in get_balances output
|
|
||||||
for currency in deepcopy(self._wallets):
|
|
||||||
if currency not in balances:
|
|
||||||
del self._wallets[currency]
|
|
||||||
|
|
||||||
positions = self._exchange.fetch_positions()
|
positions = self._exchange.fetch_positions()
|
||||||
_parsed_positions = {}
|
_parsed_positions = {}
|
||||||
@@ -210,6 +206,7 @@ class Wallets:
|
|||||||
side=position["side"],
|
side=position["side"],
|
||||||
)
|
)
|
||||||
self._positions = _parsed_positions
|
self._positions = _parsed_positions
|
||||||
|
self._wallets = _wallets
|
||||||
|
|
||||||
def update(self, require_update: bool = True) -> None:
|
def update(self, require_update: bool = True) -> None:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user