diff --git a/freqtrade/finance/wallets.py b/freqtrade/finance/wallets.py new file mode 100644 index 000000000..c8d8bab2f --- /dev/null +++ b/freqtrade/finance/wallets.py @@ -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() diff --git a/freqtrade/persistence.py b/freqtrade/persistence.py index ac7833d79..82daa0b74 100644 --- a/freqtrade/persistence.py +++ b/freqtrade/persistence.py @@ -346,26 +346,3 @@ class Trade(_DECL_BASE): ) profit_percent = (close_trade_price / open_trade_price) - 1 return float(f"{profit_percent:.8f}") - - -class Wallet(_DECL_BASE): - """ - Class for wallet structure - It is a mirror of wallets on an exchange - """ - __tablename__ = 'wallets' - - exchange = Column(String, nullable=False, primary_key=True, index=True) - currency = Column(String, nullable=False, primary_key=True, index=True) - - free = Column(Float, index=True) - used = Column(Float) - total = Column(Float) - base = Column(Boolean, index=True, default=False) - quote = Column(Boolean, index=True, default=False) - - __table_args__ = ( - PrimaryKeyConstraint( - exchange, - currency), - {})