added tests to /balance, minor cleanup

This commit is contained in:
Samuel Husso 2017-10-29 10:10:00 +02:00
parent dd78c62c3d
commit 4f6c3f94e0
2 changed files with 23 additions and 5 deletions

View File

@ -208,19 +208,18 @@ def _balance(bot: Bot, update: Update) -> None:
Hander for /balance
Returns current account balance per crypto
"""
filter = {'Currency', 'CryptoAddress'}
output = ""
balances = exchange.get_balances()
for c in balances:
# output[c['Currency']] = {k: c[k] for k in c.keys() & {*set(c) - set(filter)}}
for currency in balances:
output += """*Currency*: {Currency}
*Available*: {Available}
*Balance*: {Balance}
*Pending*: {Pending}
""".format(**c)
""".format(**currency)
send_msg(output)
@authorized_only
@ -347,6 +346,7 @@ def _help(bot: Bot, update: Update) -> None:
*/profit:* `Lists cumulative profit from all finished trades`
*/forcesell <trade_id>:* `Instantly sells the given trade, regardless of profit`
*/performance:* `Show performance of each finished trade grouped by pair`
*/balance:* `Show account balance per currency`
*/help:* `This help message`
"""
send_msg(message, bot=bot)

View File

@ -9,7 +9,7 @@ from telegram import Bot, Update, Message, Chat
from freqtrade.main import init, create_trade
from freqtrade.misc import update_state, State, get_state, CONF_SCHEMA
from freqtrade.persistence import Trade
from freqtrade.rpc.telegram import _status, _profit, _forcesell, _performance, _start, _stop
from freqtrade.rpc.telegram import _status, _profit, _forcesell, _performance, _start, _stop, _balance
@pytest.fixture
@ -197,3 +197,21 @@ def test_stop_handle(conf, update, mocker):
assert get_state() == State.STOPPED
assert msg_mock.call_count == 1
assert 'Stopping trader' in msg_mock.call_args_list[0][0][0]
def test_balance_handle(conf, update, mocker):
mock_balance = [{
'Currency': 'BTC',
'Balance': 10.0,
'Available': 12.0,
'Pending': 0.0,
'CryptoAddress': 'XXXX'}]
mocker.patch.dict('freqtrade.main._CONF', conf)
msg_mock = MagicMock()
mocker.patch.multiple('freqtrade.main.telegram', _CONF=conf, init=MagicMock(), send_msg=msg_mock)
mocker.patch.multiple('freqtrade.main.exchange',
get_balances=MagicMock(return_value=mock_balance))
_balance(bot=MagicBot(), 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]