Merge pull request #453 from ermakus/fix_usdt_balance

Fix usdt balance
This commit is contained in:
Janne Sinivirta 2018-01-29 08:48:38 +02:00 committed by GitHub
commit 21b142df40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 5 deletions

View File

@ -390,13 +390,17 @@ def _balance(bot: Bot, update: Update) -> None:
if c['Balance'] or c['Available'] or c['Pending']
]
if not balances:
output = '`All balances are zero.`'
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:
if coin == 'USDT':
currency["Rate"] = 1.0 / exchange.get_ticker('USDT_BTC', False)['bid']
else:
currency["Rate"] = exchange.get_ticker('BTC_' + coin, False)['bid']
currency['BTC'] = currency["Rate"] * currency["Balance"]

View File

@ -631,6 +631,7 @@ def test_stop_handle_already_stopped(default_conf, update, mocker):
def test_balance_handle(default_conf, update, mocker):
mock_balance = [{
'Currency': 'BTC',
'Balance': 10.0,
@ -643,7 +644,34 @@ def test_balance_handle(default_conf, update, mocker):
'Available': 0.0,
'Pending': 0.0,
'CryptoAddress': 'XXXX',
}, {
'Currency': 'USDT',
'Balance': 10000.0,
'Available': 0.0,
'Pending': 0.0,
'CryptoAddress': 'XXXX',
}, {
'Currency': 'LTC',
'Balance': 10.0,
'Available': 10.0,
'Pending': 0.0,
'CryptoAddress': 'XXXX',
}]
def mock_ticker(symbol, refresh):
if symbol == 'USDT_BTC':
return {
'bid': 10000.00,
'ask': 10000.00,
'last': 10000.00,
}
else:
return {
'bid': 0.1,
'ask': 0.1,
'last': 0.1,
}
mocker.patch.dict('freqtrade.main._CONF', default_conf)
msg_mock = MagicMock()
mocker.patch.multiple('freqtrade.rpc.telegram',
@ -655,12 +683,32 @@ def test_balance_handle(default_conf, update, mocker):
mocker.patch.multiple('freqtrade.fiat_convert.Pymarketcap',
ticker=MagicMock(return_value={'price_usd': 15000.0}),
_cache_symbols=MagicMock(return_value={'BTC': 1}))
mocker.patch('freqtrade.main.exchange.get_ticker', side_effect=mock_ticker)
_balance(bot=MagicMock(), update=update)
result = msg_mock.call_args_list[0][0][0]
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]
assert '*Currency*: BTC' in result
assert '*Currency*: ETH' not in result
assert '*Currency*: USDT' in result
assert 'Balance' in result
assert 'Est. BTC' in result
assert '*BTC*: 12.00000000' in result
def test_zero_balance_handle(default_conf, update, mocker):
mocker.patch.dict('freqtrade.main._CONF', default_conf)
msg_mock = MagicMock()
mocker.patch.multiple('freqtrade.rpc.telegram',
_CONF=default_conf,
init=MagicMock(),
send_msg=msg_mock)
mocker.patch.multiple('freqtrade.main.exchange',
get_balances=MagicMock(return_value=[]))
_balance(bot=MagicMock(), update=update)
result = msg_mock.call_args_list[0][0][0]
assert msg_mock.call_count == 1
assert '`All balances are zero.`' in result
def test_help_handle(default_conf, update, mocker):