wallets cleanup

This commit is contained in:
hroff-1902
2019-03-01 01:26:29 +03:00
parent 58c296c1ff
commit 4df44d8b32
4 changed files with 45 additions and 40 deletions

View File

@@ -1,15 +1,16 @@
# pragma pylint: disable=W0603
""" Wallet """
import logging
from typing import Dict, Any, NamedTuple
from typing import Dict, NamedTuple
from freqtrade.exchange import Exchange
from freqtrade import constants
logger = logging.getLogger(__name__)
# wallet data structure
class Wallet(NamedTuple):
exchange: str
currency: str
free: float = 0
used: float = 0
@@ -18,17 +19,19 @@ class Wallet(NamedTuple):
class Wallets(object):
def __init__(self, exchange: Exchange) -> None:
self.exchange = exchange
self.wallets: Dict[str, Any] = {}
def __init__(self, config: dict, exchange: Exchange) -> None:
self._config = config
self._exchange = exchange
self._wallets: Dict[str, Wallet] = {}
self.update()
def get_free(self, currency) -> float:
if self.exchange._conf['dry_run']:
return 999.9
if self._config['dry_run']:
return self._config.get('dry_run_wallet', constants.DRY_RUN_WALLET)
balance = self.wallets.get(currency)
balance = self._wallets.get(currency)
if balance and balance.free:
return balance.free
else:
@@ -36,10 +39,10 @@ class Wallets(object):
def get_used(self, currency) -> float:
if self.exchange._conf['dry_run']:
return 999.9
if self._config['dry_run']:
return self._config.get('dry_run_wallet', constants.DRY_RUN_WALLET)
balance = self.wallets.get(currency)
balance = self._wallets.get(currency)
if balance and balance.used:
return balance.used
else:
@@ -47,25 +50,25 @@ class Wallets(object):
def get_total(self, currency) -> float:
if self.exchange._conf['dry_run']:
return 999.9
if self._config['dry_run']:
return self._config.get('dry_run_wallet', constants.DRY_RUN_WALLET)
balance = self.wallets.get(currency)
balance = self._wallets.get(currency)
if balance and balance.total:
return balance.total
else:
return 0
def update(self) -> None:
balances = self.exchange.get_balances()
balances = self._exchange.get_balances()
for currency in balances:
self.wallets[currency] = Wallet(
self.exchange.id,
self._wallets[currency] = Wallet(
currency,
balances[currency].get('free', None),
balances[currency].get('used', None),
balances[currency].get('total', None)
)
logger.info('Wallets synced ...')
logger.info('Wallets synced.')