show /balance in stake currency

This commit is contained in:
Matthias
2019-11-15 06:33:07 +01:00
parent 62d50f512d
commit 1bf8d8cff3
6 changed files with 38 additions and 27 deletions

View File

@@ -297,7 +297,7 @@ class RPC:
'best_rate': round(bp_rate * 100, 2),
}
def _rpc_balance(self, fiat_display_currency: str) -> Dict:
def _rpc_balance(self, stake_currency: str, fiat_display_currency: str) -> Dict:
""" Returns current account balance per crypto """
output = []
total = 0.0
@@ -310,27 +310,29 @@ class RPC:
if not balance['total']:
continue
if coin == 'BTC':
est_stake: float = 0
if coin == stake_currency:
rate = 1.0
est_stake = balance['total']
else:
try:
pair = self._freqtrade.exchange.get_valid_pair_combination(coin, "BTC")
if pair.startswith("BTC"):
rate = 1.0 / tickers.get(pair, {}).get('bid', 1)
else:
rate = tickers.get(pair, {}).get('bid', 1)
pair = self._freqtrade.exchange.get_valid_pair_combination(coin, stake_currency)
rate = tickers.get(pair, {}).get('bid', None)
if rate:
if pair.startswith(stake_currency):
rate = 1.0 / rate
est_stake = rate * balance['total']
except (TemporaryError, DependencyException):
logger.warning(f" Could not get rate for pair {coin}.")
continue
est_btc: float = rate * balance['total']
total = total + est_btc
total = total + (est_stake or 0)
output.append({
'currency': coin,
'free': balance['free'] if balance['free'] is not None else 0,
'balance': balance['total'] if balance['total'] is not None else 0,
'used': balance['used'] if balance['used'] is not None else 0,
'est_btc': est_btc,
'est_stake': est_stake or 0,
'stake': stake_currency,
})
if total == 0.0:
if self._freqtrade.config.get('dry_run', False):