wallets cleanup
This commit is contained in:
commit
aa15312670
@ -20,6 +20,7 @@ REQUIRED_ORDERTYPES = ['buy', 'sell', 'stoploss', 'stoploss_on_exchange']
|
||||
ORDERTYPE_POSSIBILITIES = ['limit', 'market']
|
||||
ORDERTIF_POSSIBILITIES = ['gtc', 'fok', 'ioc']
|
||||
AVAILABLE_PAIRLISTS = ['StaticPairList', 'VolumePairList']
|
||||
DRY_RUN_WALLET = 999.9
|
||||
|
||||
TICKER_INTERVAL_MINUTES = {
|
||||
'1m': 1,
|
||||
@ -60,6 +61,7 @@ CONF_SCHEMA = {
|
||||
},
|
||||
'fiat_display_currency': {'type': 'string', 'enum': SUPPORTED_FIAT},
|
||||
'dry_run': {'type': 'boolean'},
|
||||
'dry_run_wallet': {'type': 'number'},
|
||||
'process_only_new_candles': {'type': 'boolean'},
|
||||
'minimal_roi': {
|
||||
'type': 'object',
|
||||
|
@ -63,7 +63,7 @@ class FreqtradeBot(object):
|
||||
exchange_name = self.config.get('exchange', {}).get('name', 'bittrex').title()
|
||||
self.exchange = ExchangeResolver(exchange_name, self.config).exchange
|
||||
|
||||
self.wallets = Wallets(self.exchange)
|
||||
self.wallets = Wallets(self.config, self.exchange)
|
||||
self.dataprovider = DataProvider(self.config, self.exchange)
|
||||
|
||||
# Attach Dataprovider to Strategy baseclass
|
||||
|
@ -23,13 +23,13 @@ def test_sync_wallet_at_boot(mocker, default_conf):
|
||||
|
||||
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
||||
|
||||
assert len(freqtrade.wallets.wallets) == 2
|
||||
assert freqtrade.wallets.wallets['BNT'].free == 1.0
|
||||
assert freqtrade.wallets.wallets['BNT'].used == 2.0
|
||||
assert freqtrade.wallets.wallets['BNT'].total == 3.0
|
||||
assert freqtrade.wallets.wallets['GAS'].free == 0.260739
|
||||
assert freqtrade.wallets.wallets['GAS'].used == 0.0
|
||||
assert freqtrade.wallets.wallets['GAS'].total == 0.260739
|
||||
assert len(freqtrade.wallets._wallets) == 2
|
||||
assert freqtrade.wallets._wallets['BNT'].free == 1.0
|
||||
assert freqtrade.wallets._wallets['BNT'].used == 2.0
|
||||
assert freqtrade.wallets._wallets['BNT'].total == 3.0
|
||||
assert freqtrade.wallets._wallets['GAS'].free == 0.260739
|
||||
assert freqtrade.wallets._wallets['GAS'].used == 0.0
|
||||
assert freqtrade.wallets._wallets['GAS'].total == 0.260739
|
||||
assert freqtrade.wallets.get_free('BNT') == 1.0
|
||||
|
||||
mocker.patch.multiple(
|
||||
@ -50,13 +50,13 @@ def test_sync_wallet_at_boot(mocker, default_conf):
|
||||
|
||||
freqtrade.wallets.update()
|
||||
|
||||
assert len(freqtrade.wallets.wallets) == 2
|
||||
assert freqtrade.wallets.wallets['BNT'].free == 1.2
|
||||
assert freqtrade.wallets.wallets['BNT'].used == 1.9
|
||||
assert freqtrade.wallets.wallets['BNT'].total == 3.5
|
||||
assert freqtrade.wallets.wallets['GAS'].free == 0.270739
|
||||
assert freqtrade.wallets.wallets['GAS'].used == 0.1
|
||||
assert freqtrade.wallets.wallets['GAS'].total == 0.260439
|
||||
assert len(freqtrade.wallets._wallets) == 2
|
||||
assert freqtrade.wallets._wallets['BNT'].free == 1.2
|
||||
assert freqtrade.wallets._wallets['BNT'].used == 1.9
|
||||
assert freqtrade.wallets._wallets['BNT'].total == 3.5
|
||||
assert freqtrade.wallets._wallets['GAS'].free == 0.270739
|
||||
assert freqtrade.wallets._wallets['GAS'].used == 0.1
|
||||
assert freqtrade.wallets._wallets['GAS'].total == 0.260439
|
||||
assert freqtrade.wallets.get_free('GAS') == 0.270739
|
||||
assert freqtrade.wallets.get_used('GAS') == 0.1
|
||||
assert freqtrade.wallets.get_total('GAS') == 0.260439
|
||||
@ -81,11 +81,11 @@ def test_sync_wallet_missing_data(mocker, default_conf):
|
||||
|
||||
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
||||
|
||||
assert len(freqtrade.wallets.wallets) == 2
|
||||
assert freqtrade.wallets.wallets['BNT'].free == 1.0
|
||||
assert freqtrade.wallets.wallets['BNT'].used == 2.0
|
||||
assert freqtrade.wallets.wallets['BNT'].total == 3.0
|
||||
assert freqtrade.wallets.wallets['GAS'].free == 0.260739
|
||||
assert freqtrade.wallets.wallets['GAS'].used is None
|
||||
assert freqtrade.wallets.wallets['GAS'].total == 0.260739
|
||||
assert len(freqtrade.wallets._wallets) == 2
|
||||
assert freqtrade.wallets._wallets['BNT'].free == 1.0
|
||||
assert freqtrade.wallets._wallets['BNT'].used == 2.0
|
||||
assert freqtrade.wallets._wallets['BNT'].total == 3.0
|
||||
assert freqtrade.wallets._wallets['GAS'].free == 0.260739
|
||||
assert freqtrade.wallets._wallets['GAS'].used is None
|
||||
assert freqtrade.wallets._wallets['GAS'].total == 0.260739
|
||||
assert freqtrade.wallets.get_free('GAS') == 0.260739
|
||||
|
@ -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.')
|
||||
|
Loading…
Reference in New Issue
Block a user