allow wallet update to be skipped if the value is fresh enough.

Value is NOT configurable, having this wrong can result in bans on the
exchange.
This commit is contained in:
Matthias 2020-01-15 06:42:53 +01:00
parent d12a2a5888
commit 4013701bdb

View File

@ -2,7 +2,10 @@
""" Wallet """ """ Wallet """
import logging import logging
from typing import Dict, NamedTuple, Any from typing import Any, Dict, NamedTuple
import arrow
from freqtrade.exchange import Exchange from freqtrade.exchange import Exchange
from freqtrade.persistence import Trade from freqtrade.persistence import Trade
@ -24,7 +27,7 @@ class Wallets:
self._exchange = exchange self._exchange = exchange
self._wallets: Dict[str, Wallet] = {} self._wallets: Dict[str, Wallet] = {}
self.start_cap = config['dry_run_wallet'] self.start_cap = config['dry_run_wallet']
self._last_wallet_refresh = 0
self.update() self.update()
def get_free(self, currency) -> float: def get_free(self, currency) -> float:
@ -95,12 +98,21 @@ class Wallets:
balances[currency].get('total', None) balances[currency].get('total', None)
) )
def update(self) -> None: def update(self, require_update: bool = True) -> None:
if self._config['dry_run']: """
self._update_dry() Updates wallets from the configured version.
else: By default, updates from the exchange.
self._update_live() Update-skipping should only be used for user-invoked /balance calls, since
logger.info('Wallets synced.') for trading operations, the latest balance is needed.
:param require_update: Allow skipping an update if balances were recently refreshed
"""
if (require_update or (self._last_wallet_refresh + 3600 < arrow.utcnow().timestamp)):
if self._config['dry_run']:
self._update_dry()
else:
self._update_live()
logger.info('Wallets synced.')
self._last_wallet_refresh = arrow.utcnow().timestamp
def get_all_balances(self) -> Dict[str, Any]: def get_all_balances(self) -> Dict[str, Any]:
return self._wallets return self._wallets