use wallets instead of doing a direct call to /balance

This commit is contained in:
Matthias 2019-11-24 19:41:51 +01:00
parent 1bf8d8cff3
commit 50350a09cd
3 changed files with 12 additions and 9 deletions

View File

@ -306,14 +306,14 @@ class RPC:
except (TemporaryError, DependencyException):
raise RPCException('Error getting current tickers.')
for coin, balance in self._freqtrade.exchange.get_balances().items():
if not balance['total']:
for coin, balance in self._freqtrade.wallets.get_all_balances().items():
if not balance.total:
continue
est_stake: float = 0
if coin == stake_currency:
rate = 1.0
est_stake = balance['total']
est_stake = balance.total
else:
try:
pair = self._freqtrade.exchange.get_valid_pair_combination(coin, stake_currency)
@ -321,16 +321,16 @@ class RPC:
if rate:
if pair.startswith(stake_currency):
rate = 1.0 / rate
est_stake = rate * balance['total']
est_stake = rate * balance.total
except (TemporaryError, DependencyException):
logger.warning(f" Could not get rate for pair {coin}.")
continue
total = total + (est_stake or 0)
output.append({
'currency': coin,
'free': balance['free'] if balance['free'] is not None else 0,
'balance': balance['total'] if balance['total'] is not None else 0,
'used': balance['used'] if balance['used'] is not None else 0,
'free': balance.free if balance.free is not None else 0,
'balance': balance.total if balance.total is not None else 0,
'used': balance.used if balance.used is not None else 0,
'est_stake': est_stake or 0,
'stake': stake_currency,
})

View File

@ -2,7 +2,7 @@
""" Wallet """
import logging
from typing import Dict, NamedTuple
from typing import Dict, NamedTuple, Any
from freqtrade.exchange import Exchange
from freqtrade import constants
@ -72,3 +72,6 @@ class Wallets:
)
logger.info('Wallets synced.')
def get_all_balances(self) -> Dict[str, Any]:
return self._wallets

View File

@ -243,9 +243,9 @@ def test_api_balance(botclient, mocker, rpc_balance):
'last': 0.1,
}
mocker.patch('freqtrade.exchange.Exchange.get_balances', return_value=rpc_balance)
mocker.patch('freqtrade.exchange.Exchange.get_ticker', side_effect=mock_ticker)
mocker.patch('freqtrade.exchange.Exchange.get_valid_pair_combination',
side_effect=lambda a, b: f"{a}/{b}")
ftbot.wallets.update()
rc = client_get(client, f"{BASE_URI}/balance")
assert_response(rc)