Improve /balance output to include starting balance and percentual change
closes #5503
This commit is contained in:
@@ -46,6 +46,13 @@ class Balances(BaseModel):
|
||||
value: float
|
||||
stake: str
|
||||
note: str
|
||||
starting_capital: float
|
||||
starting_capital_ratio: float
|
||||
starting_capital_pct: float
|
||||
starting_capital_fiat: float
|
||||
starting_capital_fiat_ratio: float
|
||||
starting_capital_fiat_pct: float
|
||||
|
||||
|
||||
|
||||
class Count(BaseModel):
|
||||
|
@@ -458,6 +458,9 @@ class RPC:
|
||||
raise RPCException('Error getting current tickers.')
|
||||
|
||||
self._freqtrade.wallets.update(require_update=False)
|
||||
starting_capital = self._freqtrade.wallets.get_starting_balance()
|
||||
starting_capital_fiat = self._fiat_converter.convert_amount(
|
||||
starting_capital, stake_currency, fiat_display_currency) if self._fiat_converter else 0
|
||||
|
||||
for coin, balance in self._freqtrade.wallets.get_all_balances().items():
|
||||
if not balance.total:
|
||||
@@ -493,15 +496,28 @@ class RPC:
|
||||
else:
|
||||
raise RPCException('All balances are zero.')
|
||||
|
||||
symbol = fiat_display_currency
|
||||
value = self._fiat_converter.convert_amount(total, stake_currency,
|
||||
symbol) if self._fiat_converter else 0
|
||||
value = self._fiat_converter.convert_amount(
|
||||
total, stake_currency, fiat_display_currency) if self._fiat_converter else 0
|
||||
|
||||
starting_capital_ratio = 0.0
|
||||
starting_capital_fiat_ratio = 0.0
|
||||
if starting_capital:
|
||||
starting_capital_ratio = (total / starting_capital) - 1
|
||||
if starting_capital_fiat:
|
||||
starting_capital_fiat_ratio = (value / starting_capital_fiat) - 1
|
||||
|
||||
return {
|
||||
'currencies': output,
|
||||
'total': total,
|
||||
'symbol': symbol,
|
||||
'symbol': fiat_display_currency,
|
||||
'value': value,
|
||||
'stake': stake_currency,
|
||||
'starting_capital': starting_capital,
|
||||
'starting_capital_ratio': starting_capital_ratio,
|
||||
'starting_capital_pct': round(starting_capital_ratio * 100, 2),
|
||||
'starting_capital_fiat': starting_capital_fiat,
|
||||
'starting_capital_fiat_ratio': starting_capital_fiat_ratio,
|
||||
'starting_capital_fiat_pct': round(starting_capital_fiat_ratio * 100, 2),
|
||||
'note': 'Simulated balances' if self._freqtrade.config['dry_run'] else ''
|
||||
}
|
||||
|
||||
|
@@ -603,12 +603,15 @@ class Telegram(RPCHandler):
|
||||
|
||||
output = ''
|
||||
if self._config['dry_run']:
|
||||
output += (
|
||||
f"*Warning:* Simulated balances in Dry Mode.\n"
|
||||
"This mode is still experimental!\n"
|
||||
"Starting capital: "
|
||||
f"`{self._config['dry_run_wallet']}` {self._config['stake_currency']}.\n"
|
||||
)
|
||||
output += "*Warning:* Simulated balances in Dry Mode.\n"
|
||||
|
||||
output += ("Starting capital: "
|
||||
f"`{result['starting_capital']}` {self._config['stake_currency']}"
|
||||
)
|
||||
output += (f" `{result['starting_capital_fiat']}` "
|
||||
f"{self._config['fiat_display_currency']}.\n"
|
||||
) if result['starting_capital_fiat'] > 0 else '.\n'
|
||||
|
||||
total_dust_balance = 0
|
||||
total_dust_currencies = 0
|
||||
for curr in result['currencies']:
|
||||
@@ -641,9 +644,13 @@ class Telegram(RPCHandler):
|
||||
f"{round_coin_value(total_dust_balance, result['stake'], False)}`\n")
|
||||
|
||||
output += ("\n*Estimated Value*:\n"
|
||||
f"\t`{result['stake']}: {result['total']: .8f}`\n"
|
||||
f"\t`{result['stake']}: "
|
||||
f"{round_coin_value(result['total'], result['stake'], False)}`"
|
||||
f" `({result['starting_capital_pct']}%)`\n"
|
||||
f"\t`{result['symbol']}: "
|
||||
f"{round_coin_value(result['value'], result['symbol'], False)}`\n")
|
||||
f"{round_coin_value(result['value'], result['symbol'], False)}`"
|
||||
f" `({result['starting_capital_fiat_pct']}%)`\n"
|
||||
)
|
||||
self._send_msg(output, reload_able=True, callback_path="update_balance",
|
||||
query=update.callback_query)
|
||||
except RPCException as e:
|
||||
|
Reference in New Issue
Block a user