Fix bug causing /balance to fail
This commit is contained in:
parent
3c451e0677
commit
e1921c8849
@ -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:
|
||||||
|
@ -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
|
||||||
@ -271,10 +272,13 @@ class RPC(object):
|
|||||||
if coin == 'BTC':
|
if coin == 'BTC':
|
||||||
rate = 1.0
|
rate = 1.0
|
||||||
else:
|
else:
|
||||||
if coin == 'USDT':
|
try:
|
||||||
rate = 1.0 / self._freqtrade.exchange.get_ticker('BTC/USDT', False)['bid']
|
if coin == 'USDT':
|
||||||
else:
|
rate = 1.0 / self._freqtrade.exchange.get_ticker('BTC/USDT', False)['bid']
|
||||||
rate = self._freqtrade.exchange.get_ticker(coin + '/BTC', False)['bid']
|
else:
|
||||||
|
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({
|
||||||
|
@ -286,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',
|
||||||
@ -302,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)
|
||||||
@ -323,31 +325,6 @@ def test_rpc_balance_handle(default_conf, mocker):
|
|||||||
}]
|
}]
|
||||||
assert result['total'] == 12.0
|
assert result['total'] == 12.0
|
||||||
|
|
||||||
mock_balance = {
|
|
||||||
'ETH': {
|
|
||||||
'free': 10.0,
|
|
||||||
'total': 12.0,
|
|
||||||
'used': 2.0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mocker.patch.multiple(
|
|
||||||
'freqtrade.exchange.Exchange',
|
|
||||||
validate_pairs=MagicMock(),
|
|
||||||
get_balances=MagicMock(return_value=mock_balance),
|
|
||||||
get_ticker=MagicMock(side_effect=TemporaryError('Could not load ticker due to xxx'))
|
|
||||||
)
|
|
||||||
result = rpc._rpc_balance(default_conf['fiat_display_currency'])
|
|
||||||
assert prec_satoshi(result['total'], 12)
|
|
||||||
assert prec_satoshi(result['value'], 180000)
|
|
||||||
assert 'USD' == result['symbol']
|
|
||||||
assert result['currencies'] == [{
|
|
||||||
'currency': 'ETH',
|
|
||||||
'available': 10.0,
|
|
||||||
'balance': 12.0,
|
|
||||||
'pending': 2.0,
|
|
||||||
'est_btc': 12.0,
|
|
||||||
}]
|
|
||||||
|
|
||||||
|
|
||||||
def test_rpc_start(mocker, default_conf) -> None:
|
def test_rpc_start(mocker, default_conf) -> None:
|
||||||
patch_coinmarketcap(mocker)
|
patch_coinmarketcap(mocker)
|
||||||
|
Loading…
Reference in New Issue
Block a user