putting wallets into a class (doesn’t need to be in persistence)

This commit is contained in:
misagh 2018-11-17 21:16:32 +01:00
parent 69dd56b237
commit 82cb0e4d95
2 changed files with 39 additions and 23 deletions

View 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()

View File

@ -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),
{})