This commit is contained in:
kryofly 2018-01-17 22:19:05 +01:00
parent bce00aeaad
commit 04ac71d9fe
3 changed files with 41 additions and 22 deletions

View File

@ -295,3 +295,35 @@ def rpc_trade_statistics(stake_currency, fiat_display_currency) -> None:
best_rate=round(bp_rate * 100, 2),
)
return markdown_msg
def rpc_balance(fiat_display_currency):
"""
:return: current account balance per crypto
"""
balances = [
c for c in exchange.get_balances()
if c['Balance'] or c['Available'] or c['Pending']
]
if not balances:
return (True, '`All balances are zero.`')
output = []
total = 0.0
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.append({'currency': currency['Currency'],
'available': currency['Available'],
'balance': currency['Balance'],
'pending': currency['Pending'],
'est_btc': currency['BTC']
})
fiat = CryptoToFiatConverter()
symbol = fiat_display_currency
value = fiat.convert_amount(total, 'BTC', symbol)
return (output, total, symbol, value)

View File

@ -10,7 +10,8 @@ from telegram.ext import CommandHandler, Updater
from freqtrade.rpc.__init__ import (rpc_status_table,
rpc_trade_status,
rpc_daily_profit,
rpc_trade_statistics
rpc_trade_statistics,
rpc_balance
)
from freqtrade import __version__, exchange
@ -243,23 +244,14 @@ def _balance(bot: Bot, update: Update) -> None:
Handler for /balance
Returns current account balance per crypto
"""
output = ''
balances = [
c for c in exchange.get_balances()
if c['Balance'] or c['Available'] or c['Pending']
]
if not balances:
output = '`All balances are zero.`'
(error, result) = rpc_balance(_CONF['fiat_display_currency'])
if error:
send_msg('`All balances are zero.`')
return
total = 0.0
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']
(currencys, total, symbol, value) = result
output = ''
for currency in currencys:
output += """*Currency*: {Currency}
*Available*: {Available}
*Balance*: {Balance}
@ -268,10 +260,6 @@ def _balance(bot: Bot, update: Update) -> None:
""".format(**currency)
symbol = _CONF['fiat_display_currency']
value = _FIAT_CONVERT.convert_amount(
total, 'BTC', symbol
)
output += """*Estimated Value*:
*BTC*: {0: .8f}
*{1}*: {2: .2f}

View File

@ -155,7 +155,6 @@ def test_rpc_trade_statistics(
default_conf, update, ticker, ticker_sell_up, limit_buy_order, limit_sell_order, mocker):
mocker.patch.dict('freqtrade.main._CONF', default_conf)
mocker.patch('freqtrade.main.get_signal', side_effect=lambda s, t: True)
msg_mock = MagicMock()
mocker.patch('freqtrade.main.rpc.send_msg', MagicMock())
mocker.patch.multiple('freqtrade.rpc.telegram',
_CONF=default_conf,