1) NamedTuple refactored 2) Missing data handled

This commit is contained in:
misagh 2018-11-21 19:47:51 +01:00
parent cb3cf960d7
commit 88f61581d9

View File

@ -1,13 +1,21 @@
# pragma pylint: disable=W0603 # pragma pylint: disable=W0603
""" Wallet """ """ Wallet """
import logging import logging
from typing import Dict, Any from typing import Dict, Any, NamedTuple
from collections import namedtuple from collections import namedtuple
from freqtrade.exchange import Exchange from freqtrade.exchange import Exchange
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class Wallet(NamedTuple):
exchange: str = None
currency: str = None
free: float = 0
used: float = 0
total: float = 0
class Wallets(object): class Wallets(object):
# wallet data structure # wallet data structure
@ -25,14 +33,12 @@ class Wallets(object):
balances = self.exchange.get_balances() balances = self.exchange.get_balances()
for currency in balances: for currency in balances:
info = { self.wallets[currency] = Wallet(
'exchange': self.exchange.id, self.exchange.id,
'currency': currency, currency,
'free': balances[currency]['free'], balances[currency].get('free', None),
'used': balances[currency]['used'], balances[currency].get('used', None),
'total': balances[currency]['total'] balances[currency].get('total', None)
} )
self.wallets[currency] = self.wallet(**info)
logger.info('Wallets synced ...') logger.info('Wallets synced ...')