stable/freqtrade/wallets.py

39 lines
1005 B
Python
Raw Normal View History

# pragma pylint: disable=W0603
""" Wallet """
import logging
2018-11-18 13:57:03 +00:00
from typing import Dict, Any
from collections import namedtuple
from freqtrade.exchange import Exchange
logger = logging.getLogger(__name__)
class Wallets(object):
# wallet data structure
wallet = namedtuple(
'wallet',
['exchange', 'currency', 'free', 'used', 'total']
)
def __init__(self, exchange: Exchange) -> None:
self.exchange = exchange
2018-11-18 13:57:03 +00:00
self.wallets: Dict[str, Any] = {}
2018-11-18 13:39:31 +00:00
self.update()
2018-11-18 13:39:31 +00:00
def update(self) -> None:
balances = self.exchange.get_balances()
for currency in balances:
info = {
'exchange': self.exchange.id,
'currency': currency,
2018-11-17 22:03:07 +00:00
'free': balances[currency]['free'],
'used': balances[currency]['used'],
'total': balances[currency]['total']
}
2018-11-17 22:03:07 +00:00
self.wallets[currency] = self.wallet(**info)
logger.info('Wallets synced ...')