Fix wrong estimated output from /balance endpoints

This commit is contained in:
Matthias 2022-03-10 06:47:17 +01:00
parent 0d754111e9
commit 98755c1874
2 changed files with 7 additions and 4 deletions

View File

@ -586,6 +586,9 @@ class RPC:
if coin == stake_currency:
rate = 1.0
est_stake = balance.total
if self._config.get('trading_mode', TradingMode.SPOT) != TradingMode.SPOT:
# in Futures, "total" includes the locked stake, and therefore all positions
est_stake = balance.free
else:
try:
pair = self._freqtrade.exchange.get_valid_pair_combination(coin, stake_currency)
@ -614,6 +617,7 @@ class RPC:
symbol: str
position: PositionWallet
for symbol, position in self._freqtrade.wallets.get_all_positions().items():
total += position.collateral
currencies.append({
'currency': symbol,

View File

@ -650,8 +650,8 @@ def test_rpc_balance_handle(default_conf, mocker, tickers):
rpc._fiat_converter = CryptoToFiatConverter()
result = rpc._rpc_balance(default_conf['stake_currency'], default_conf['fiat_display_currency'])
assert prec_satoshi(result['total'], 12.309096315)
assert prec_satoshi(result['value'], 184636.44472997)
assert prec_satoshi(result['total'], 30.309096315)
assert prec_satoshi(result['value'], 454636.44472997)
assert tickers.call_count == 1
assert tickers.call_args_list[0][1]['cached'] is True
assert 'USD' == result['symbol']
@ -661,7 +661,7 @@ def test_rpc_balance_handle(default_conf, mocker, tickers):
'free': 10.0,
'balance': 12.0,
'used': 2.0,
'est_stake': 12.0,
'est_stake': 10.0, # In futures mode, "free" is used here.
'stake': 'BTC',
'is_position': False,
'leverage': 1.0,
@ -706,7 +706,6 @@ def test_rpc_balance_handle(default_conf, mocker, tickers):
'side': 'short',
}
]
assert result['total'] == 12.309096315331816
def test_rpc_start(mocker, default_conf) -> None: