putting wallets into a class (doesn’t need to be in persistence)
This commit is contained in:
39
freqtrade/finance/wallets.py
Normal file
39
freqtrade/finance/wallets.py
Normal file
@@ -0,0 +1,39 @@
|
||||
# pragma pylint: disable=W0603
|
||||
""" Wallet """
|
||||
import logging
|
||||
from typing import Dict
|
||||
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
|
||||
self.wallets: Dict[str, self.wallet] = {}
|
||||
|
||||
def _update_wallets(self) -> None:
|
||||
balances = self.exchange.get_balances()
|
||||
|
||||
for currency in balances:
|
||||
info = {
|
||||
'exchange': self.exchange.id,
|
||||
'currency': currency,
|
||||
'free': balances[currency['free']],
|
||||
'used': balances[currency['used']],
|
||||
'total': balances[currency['total']]
|
||||
}
|
||||
self.wallets[currency] = self.wallet(**info)
|
||||
|
||||
logger.info('Wallets synced ...')
|
||||
|
||||
def update(self) -> None:
|
||||
self._update_wallets()
|
Reference in New Issue
Block a user