Merge pull request #386 from ermakus/show_estimated_btc_fiat_balance

Show estimated BTC and fiat balance
This commit is contained in:
Samuel Husso 2018-01-15 09:13:42 +02:00 committed by GitHub
commit 354dcaac58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -382,13 +382,31 @@ def _balance(bot: Bot, update: Update) -> None:
if not balances: if not balances:
output = '`All balances are zero.`' output = '`All balances are zero.`'
total = 0.0
for currency in balances: for currency in balances:
coin = currency['Currency']
if coin == 'BTC':
currency["Rate"] = 1.0
else:
currency["Rate"] = exchange.get_ticker('BTC_' + coin, False)['bid']
currency['BTC'] = currency["Rate"] * currency["Balance"]
total = total + currency['BTC']
output += """*Currency*: {Currency} output += """*Currency*: {Currency}
*Available*: {Available} *Available*: {Available}
*Balance*: {Balance} *Balance*: {Balance}
*Pending*: {Pending} *Pending*: {Pending}
*Est. BTC*: {BTC: .8f}
""".format(**currency) """.format(**currency)
symbol = _CONF['fiat_display_currency']
value = _FIAT_CONVERT.convert_amount(
total, 'BTC', symbol
)
output += """*Estimated Value*:
*BTC*: {0: .8f}
*{1}*: {2: .2f}
""".format(total, symbol, value)
send_msg(output) send_msg(output)

View File

@ -606,11 +606,15 @@ def test_balance_handle(default_conf, update, mocker):
send_msg=msg_mock) send_msg=msg_mock)
mocker.patch.multiple('freqtrade.main.exchange', mocker.patch.multiple('freqtrade.main.exchange',
get_balances=MagicMock(return_value=mock_balance)) get_balances=MagicMock(return_value=mock_balance))
mocker.patch.multiple('freqtrade.fiat_convert.Pymarketcap',
ticker=MagicMock(return_value={'price_usd': 15000.0}),
_cache_symbols=MagicMock(return_value={'BTC': 1}))
_balance(bot=MagicMock(), update=update) _balance(bot=MagicMock(), update=update)
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert '*Currency*: BTC' in msg_mock.call_args_list[0][0][0] assert '*Currency*: BTC' in msg_mock.call_args_list[0][0][0]
assert 'Balance' in msg_mock.call_args_list[0][0][0] assert 'Balance' in msg_mock.call_args_list[0][0][0]
assert 'Est. BTC' in msg_mock.call_args_list[0][0][0]
def test_help_handle(default_conf, update, mocker): def test_help_handle(default_conf, update, mocker):