Use last to get rates for /balance endpoints

This commit is contained in:
Matthias 2022-03-13 17:53:52 +01:00
parent 32c06f4a05
commit c63b5fbbbf
2 changed files with 5 additions and 6 deletions

View File

@ -582,7 +582,7 @@ class RPC:
else: else:
try: try:
pair = self._freqtrade.exchange.get_valid_pair_combination(coin, stake_currency) pair = self._freqtrade.exchange.get_valid_pair_combination(coin, stake_currency)
rate = tickers.get(pair, {}).get('bid', None) rate = tickers.get(pair, {}).get('last', None)
if rate: if rate:
if pair.startswith(stake_currency) and not pair.endswith(stake_currency): if pair.startswith(stake_currency) and not pair.endswith(stake_currency):
rate = 1.0 / rate rate = 1.0 / rate

View File

@ -605,8 +605,8 @@ def test_rpc_balance_handle(default_conf, mocker, tickers):
rpc._fiat_converter = CryptoToFiatConverter() rpc._fiat_converter = CryptoToFiatConverter()
result = rpc._rpc_balance(default_conf['stake_currency'], default_conf['fiat_display_currency']) result = rpc._rpc_balance(default_conf['stake_currency'], default_conf['fiat_display_currency'])
assert prec_satoshi(result['total'], 12.309096315) assert prec_satoshi(result['total'], 12.30909624)
assert prec_satoshi(result['value'], 184636.44472997) assert prec_satoshi(result['value'], 184636.443606915)
assert tickers.call_count == 1 assert tickers.call_count == 1
assert tickers.call_args_list[0][1]['cached'] is True assert tickers.call_args_list[0][1]['cached'] is True
assert 'USD' == result['symbol'] assert 'USD' == result['symbol']
@ -624,17 +624,16 @@ def test_rpc_balance_handle(default_conf, mocker, tickers):
'est_stake': 0.30794, 'est_stake': 0.30794,
'used': 4.0, 'used': 4.0,
'stake': 'BTC', 'stake': 'BTC',
}, },
{'free': 5.0, {'free': 5.0,
'balance': 10.0, 'balance': 10.0,
'currency': 'USDT', 'currency': 'USDT',
'est_stake': 0.0011563153318162476, 'est_stake': 0.0011562404610161968,
'used': 5.0, 'used': 5.0,
'stake': 'BTC', 'stake': 'BTC',
} }
] ]
assert result['total'] == 12.309096315331816 assert result['total'] == 12.309096240461017
def test_rpc_start(mocker, default_conf) -> None: def test_rpc_start(mocker, default_conf) -> None: