From dd9ab5264df2fdf9d26b132ab7c38b52eae8b2cb Mon Sep 17 00:00:00 2001 From: Anton Ermak Date: Sat, 13 Jan 2018 14:58:23 +0700 Subject: [PATCH 1/2] Estimated BTC and fiat value for balance --- freqtrade/rpc/telegram.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 009714682..a5c07d75c 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -382,13 +382,31 @@ def _balance(bot: Bot, update: Update) -> None: if not balances: output = '`All balances are zero.`' + total = 0.0 for currency in balances: - output += """*Currency*: {Currency} + 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}: *Available*: {Available} *Balance*: {Balance} *Pending*: {Pending} +*Est. BTC*: {BTC: .8f} """.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) From 5db04b15e721400594b5789312fd22abeafae81c Mon Sep 17 00:00:00 2001 From: Anton Ermak Date: Mon, 15 Jan 2018 12:07:01 +0700 Subject: [PATCH 2/2] Balance Estimated BTC - fix test --- freqtrade/rpc/telegram.py | 2 +- freqtrade/tests/rpc/test_rpc_telegram.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index a5c07d75c..12e701a1c 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -391,7 +391,7 @@ def _balance(bot: Bot, update: Update) -> None: currency["Rate"] = exchange.get_ticker('BTC_' + coin, False)['bid'] currency['BTC'] = currency["Rate"] * currency["Balance"] total = total + currency['BTC'] - output += """{Currency}: + output += """*Currency*: {Currency} *Available*: {Available} *Balance*: {Balance} *Pending*: {Pending} diff --git a/freqtrade/tests/rpc/test_rpc_telegram.py b/freqtrade/tests/rpc/test_rpc_telegram.py index 428c544c1..58bf0154b 100644 --- a/freqtrade/tests/rpc/test_rpc_telegram.py +++ b/freqtrade/tests/rpc/test_rpc_telegram.py @@ -606,11 +606,15 @@ def test_balance_handle(default_conf, update, mocker): send_msg=msg_mock) mocker.patch.multiple('freqtrade.main.exchange', 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) assert msg_mock.call_count == 1 assert '*Currency*: BTC' 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):