use wallets instead of doing a direct call to /balance
This commit is contained in:
parent
1bf8d8cff3
commit
50350a09cd
@ -306,14 +306,14 @@ class RPC:
|
|||||||
except (TemporaryError, DependencyException):
|
except (TemporaryError, DependencyException):
|
||||||
raise RPCException('Error getting current tickers.')
|
raise RPCException('Error getting current tickers.')
|
||||||
|
|
||||||
for coin, balance in self._freqtrade.exchange.get_balances().items():
|
for coin, balance in self._freqtrade.wallets.get_all_balances().items():
|
||||||
if not balance['total']:
|
if not balance.total:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
est_stake: float = 0
|
est_stake: float = 0
|
||||||
if coin == stake_currency:
|
if coin == stake_currency:
|
||||||
rate = 1.0
|
rate = 1.0
|
||||||
est_stake = balance['total']
|
est_stake = balance.total
|
||||||
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)
|
||||||
@ -321,16 +321,16 @@ class RPC:
|
|||||||
if rate:
|
if rate:
|
||||||
if pair.startswith(stake_currency):
|
if pair.startswith(stake_currency):
|
||||||
rate = 1.0 / rate
|
rate = 1.0 / rate
|
||||||
est_stake = rate * balance['total']
|
est_stake = rate * balance.total
|
||||||
except (TemporaryError, DependencyException):
|
except (TemporaryError, DependencyException):
|
||||||
logger.warning(f" Could not get rate for pair {coin}.")
|
logger.warning(f" Could not get rate for pair {coin}.")
|
||||||
continue
|
continue
|
||||||
total = total + (est_stake or 0)
|
total = total + (est_stake or 0)
|
||||||
output.append({
|
output.append({
|
||||||
'currency': coin,
|
'currency': coin,
|
||||||
'free': balance['free'] if balance['free'] 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,
|
'balance': balance.total if balance.total is not None else 0,
|
||||||
'used': balance['used'] if balance['used'] is not None else 0,
|
'used': balance.used if balance.used is not None else 0,
|
||||||
'est_stake': est_stake or 0,
|
'est_stake': est_stake or 0,
|
||||||
'stake': stake_currency,
|
'stake': stake_currency,
|
||||||
})
|
})
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
""" Wallet """
|
""" Wallet """
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Dict, NamedTuple
|
from typing import Dict, NamedTuple, Any
|
||||||
from freqtrade.exchange import Exchange
|
from freqtrade.exchange import Exchange
|
||||||
from freqtrade import constants
|
from freqtrade import constants
|
||||||
|
|
||||||
@ -72,3 +72,6 @@ class Wallets:
|
|||||||
)
|
)
|
||||||
|
|
||||||
logger.info('Wallets synced.')
|
logger.info('Wallets synced.')
|
||||||
|
|
||||||
|
def get_all_balances(self) -> Dict[str, Any]:
|
||||||
|
return self._wallets
|
||||||
|
@ -243,9 +243,9 @@ def test_api_balance(botclient, mocker, rpc_balance):
|
|||||||
'last': 0.1,
|
'last': 0.1,
|
||||||
}
|
}
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_balances', return_value=rpc_balance)
|
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',
|
mocker.patch('freqtrade.exchange.Exchange.get_valid_pair_combination',
|
||||||
side_effect=lambda a, b: f"{a}/{b}")
|
side_effect=lambda a, b: f"{a}/{b}")
|
||||||
|
ftbot.wallets.update()
|
||||||
|
|
||||||
rc = client_get(client, f"{BASE_URI}/balance")
|
rc = client_get(client, f"{BASE_URI}/balance")
|
||||||
assert_response(rc)
|
assert_response(rc)
|
||||||
|
Loading…
Reference in New Issue
Block a user