Merge pull request #1135 from freqtrade/fix/rpc_balance_vtho

Fix /balance rpc call if coin is not properly listed
This commit is contained in:
Samuel Husso 2018-08-22 07:01:40 +03:00 committed by GitHub
commit 36e0e652f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 9 deletions

View File

@ -322,7 +322,7 @@ class Exchange(object):
return data return data
except (ccxt.NetworkError, ccxt.ExchangeError) as e: except (ccxt.NetworkError, ccxt.ExchangeError) as e:
raise TemporaryError( raise TemporaryError(
f'Could not load ticker history due to {e.__class__.__name__}. Message: {e}') f'Could not load ticker due to {e.__class__.__name__}. Message: {e}')
except ccxt.BaseError as e: except ccxt.BaseError as e:
raise OperationalException(e) raise OperationalException(e)
else: else:

View File

@ -13,6 +13,7 @@ import sqlalchemy as sql
from numpy import mean, nan_to_num from numpy import mean, nan_to_num
from pandas import DataFrame from pandas import DataFrame
from freqtrade import TemporaryError
from freqtrade.fiat_convert import CryptoToFiatConverter from freqtrade.fiat_convert import CryptoToFiatConverter
from freqtrade.misc import shorten_date from freqtrade.misc import shorten_date
from freqtrade.persistence import Trade from freqtrade.persistence import Trade
@ -273,10 +274,13 @@ class RPC(object):
if coin == 'BTC': if coin == 'BTC':
rate = 1.0 rate = 1.0
else: else:
try:
if coin == 'USDT': if coin == 'USDT':
rate = 1.0 / self._freqtrade.exchange.get_ticker('BTC/USDT', False)['bid'] rate = 1.0 / self._freqtrade.exchange.get_ticker('BTC/USDT', False)['bid']
else: else:
rate = self._freqtrade.exchange.get_ticker(coin + '/BTC', False)['bid'] rate = self._freqtrade.exchange.get_ticker(coin + '/BTC', False)['bid']
except TemporaryError:
continue
est_btc: float = rate * balance['total'] est_btc: float = rate * balance['total']
total = total + est_btc total = total + est_btc
output.append({ output.append({

View File

@ -6,6 +6,7 @@ from unittest.mock import MagicMock, ANY
import pytest import pytest
from freqtrade import TemporaryError
from freqtrade.fiat_convert import CryptoToFiatConverter from freqtrade.fiat_convert import CryptoToFiatConverter
from freqtrade.freqtradebot import FreqtradeBot from freqtrade.freqtradebot import FreqtradeBot
from freqtrade.persistence import Trade from freqtrade.persistence import Trade
@ -285,11 +286,12 @@ def test_rpc_balance_handle(default_conf, mocker):
'used': 2.0, 'used': 2.0,
}, },
'ETH': { 'ETH': {
'free': 0.0, 'free': 1.0,
'total': 0.0, 'total': 5.0,
'used': 0.0, 'used': 4.0,
} }
} }
# ETH will be skipped due to mocked Error below
mocker.patch.multiple( mocker.patch.multiple(
'freqtrade.fiat_convert.Market', 'freqtrade.fiat_convert.Market',
@ -301,7 +303,8 @@ def test_rpc_balance_handle(default_conf, mocker):
mocker.patch.multiple( mocker.patch.multiple(
'freqtrade.exchange.Exchange', 'freqtrade.exchange.Exchange',
validate_pairs=MagicMock(), validate_pairs=MagicMock(),
get_balances=MagicMock(return_value=mock_balance) get_balances=MagicMock(return_value=mock_balance),
get_ticker=MagicMock(side_effect=TemporaryError('Could not load ticker due to xxx'))
) )
freqtradebot = FreqtradeBot(default_conf) freqtradebot = FreqtradeBot(default_conf)
@ -320,6 +323,7 @@ def test_rpc_balance_handle(default_conf, mocker):
'pending': 2.0, 'pending': 2.0,
'est_btc': 12.0, 'est_btc': 12.0,
}] }]
assert result['total'] == 12.0
def test_rpc_start(mocker, default_conf) -> None: def test_rpc_start(mocker, default_conf) -> None: