Wallets should use trade_proxy
This commit is contained in:
parent
9968e4e49c
commit
f0a154692d
@ -11,6 +11,7 @@ from freqtrade.constants import UNLIMITED_STAKE_AMOUNT
|
|||||||
from freqtrade.exceptions import DependencyException
|
from freqtrade.exceptions import DependencyException
|
||||||
from freqtrade.exchange import Exchange
|
from freqtrade.exchange import Exchange
|
||||||
from freqtrade.persistence import Trade
|
from freqtrade.persistence import Trade
|
||||||
|
from freqtrade.state import RunMode
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -26,13 +27,14 @@ class Wallet(NamedTuple):
|
|||||||
|
|
||||||
class Wallets:
|
class Wallets:
|
||||||
|
|
||||||
def __init__(self, config: dict, exchange: Exchange) -> None:
|
def __init__(self, config: dict, exchange: Exchange, skip_update: bool = False) -> None:
|
||||||
self._config = config
|
self._config = config
|
||||||
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._last_wallet_refresh = 0
|
||||||
self.update()
|
if not skip_update:
|
||||||
|
self.update()
|
||||||
|
|
||||||
def get_free(self, currency: str) -> float:
|
def get_free(self, currency: str) -> float:
|
||||||
balance = self._wallets.get(currency)
|
balance = self._wallets.get(currency)
|
||||||
@ -64,8 +66,8 @@ class Wallets:
|
|||||||
"""
|
"""
|
||||||
# Recreate _wallets to reset closed trade balances
|
# Recreate _wallets to reset closed trade balances
|
||||||
_wallets = {}
|
_wallets = {}
|
||||||
closed_trades = Trade.get_trades(Trade.is_open.is_(False)).all()
|
closed_trades = Trade.get_trades_proxy(is_open=False)
|
||||||
open_trades = Trade.get_trades(Trade.is_open.is_(True)).all()
|
open_trades = Trade.get_trades_proxy(is_open=True)
|
||||||
tot_profit = sum([trade.calc_profit() for trade in closed_trades])
|
tot_profit = sum([trade.calc_profit() for trade in closed_trades])
|
||||||
tot_in_trades = sum([trade.stake_amount for trade in open_trades])
|
tot_in_trades = sum([trade.stake_amount for trade in open_trades])
|
||||||
|
|
||||||
@ -102,7 +104,7 @@ class Wallets:
|
|||||||
if currency not in balances:
|
if currency not in balances:
|
||||||
del self._wallets[currency]
|
del self._wallets[currency]
|
||||||
|
|
||||||
def update(self, require_update: bool = True) -> None:
|
def update(self, require_update: bool = True, log: bool = True) -> None:
|
||||||
"""
|
"""
|
||||||
Updates wallets from the configured version.
|
Updates wallets from the configured version.
|
||||||
By default, updates from the exchange.
|
By default, updates from the exchange.
|
||||||
@ -111,11 +113,12 @@ class Wallets:
|
|||||||
:param require_update: Allow skipping an update if balances were recently refreshed
|
:param require_update: Allow skipping an update if balances were recently refreshed
|
||||||
"""
|
"""
|
||||||
if (require_update or (self._last_wallet_refresh + 3600 < arrow.utcnow().int_timestamp)):
|
if (require_update or (self._last_wallet_refresh + 3600 < arrow.utcnow().int_timestamp)):
|
||||||
if self._config['dry_run']:
|
if (not self._config['dry_run'] or self._config.get('runmode') == RunMode.LIVE):
|
||||||
self._update_dry()
|
|
||||||
else:
|
|
||||||
self._update_live()
|
self._update_live()
|
||||||
logger.info('Wallets synced.')
|
else:
|
||||||
|
self._update_dry()
|
||||||
|
if log:
|
||||||
|
logger.info('Wallets synced.')
|
||||||
self._last_wallet_refresh = arrow.utcnow().int_timestamp
|
self._last_wallet_refresh = arrow.utcnow().int_timestamp
|
||||||
|
|
||||||
def get_all_balances(self) -> Dict[str, Any]:
|
def get_all_balances(self) -> Dict[str, Any]:
|
||||||
|
Loading…
Reference in New Issue
Block a user