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:
parent
d12a2a5888
commit
4013701bdb
@ -2,7 +2,10 @@
|
||||
""" Wallet """
|
||||
|
||||
import logging
|
||||
from typing import Dict, NamedTuple, Any
|
||||
from typing import Any, Dict, NamedTuple
|
||||
|
||||
import arrow
|
||||
|
||||
from freqtrade.exchange import Exchange
|
||||
from freqtrade.persistence import Trade
|
||||
|
||||
@ -24,7 +27,7 @@ class Wallets:
|
||||
self._exchange = exchange
|
||||
self._wallets: Dict[str, Wallet] = {}
|
||||
self.start_cap = config['dry_run_wallet']
|
||||
|
||||
self._last_wallet_refresh = 0
|
||||
self.update()
|
||||
|
||||
def get_free(self, currency) -> float:
|
||||
@ -95,12 +98,21 @@ class Wallets:
|
||||
balances[currency].get('total', None)
|
||||
)
|
||||
|
||||
def update(self) -> None:
|
||||
if self._config['dry_run']:
|
||||
self._update_dry()
|
||||
else:
|
||||
self._update_live()
|
||||
logger.info('Wallets synced.')
|
||||
def update(self, require_update: bool = True) -> None:
|
||||
"""
|
||||
Updates wallets from the configured version.
|
||||
By default, updates from the exchange.
|
||||
Update-skipping should only be used for user-invoked /balance calls, since
|
||||
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]:
|
||||
return self._wallets
|
||||
|
Loading…
Reference in New Issue
Block a user