2018-11-17 20:16:32 +00:00
|
|
|
# pragma pylint: disable=W0603
|
|
|
|
""" Wallet """
|
|
|
|
import logging
|
2018-11-21 22:36:48 +00:00
|
|
|
from typing import Dict, Any, NamedTuple
|
2018-11-17 20:16:32 +00:00
|
|
|
from collections import namedtuple
|
|
|
|
from freqtrade.exchange import Exchange
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2018-11-21 18:47:51 +00:00
|
|
|
class Wallet(NamedTuple):
|
2018-11-21 22:35:44 +00:00
|
|
|
exchange: str
|
|
|
|
currency: str
|
2018-11-21 18:47:51 +00:00
|
|
|
free: float = 0
|
|
|
|
used: float = 0
|
|
|
|
total: float = 0
|
|
|
|
|
|
|
|
|
2018-11-17 20:16:32 +00:00
|
|
|
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-17 20:16:32 +00:00
|
|
|
|
2018-11-18 13:39:31 +00:00
|
|
|
def update(self) -> None:
|
2018-11-17 20:16:32 +00:00
|
|
|
balances = self.exchange.get_balances()
|
|
|
|
|
|
|
|
for currency in balances:
|
2018-11-21 18:47:51 +00:00
|
|
|
self.wallets[currency] = Wallet(
|
|
|
|
self.exchange.id,
|
|
|
|
currency,
|
|
|
|
balances[currency].get('free', None),
|
|
|
|
balances[currency].get('used', None),
|
|
|
|
balances[currency].get('total', None)
|
|
|
|
)
|
2018-11-17 20:16:32 +00:00
|
|
|
|
|
|
|
logger.info('Wallets synced ...')
|