get_balance: handle case if currency is not in response

This commit is contained in:
gcarq 2018-04-23 16:57:18 +02:00
parent 20af4bae7c
commit baeeaa777d

View File

@ -198,13 +198,19 @@ def sell(pair: str, rate: float, amount: float) -> Dict:
raise OperationalException(e)
@retrier
def get_balance(currency: str) -> float:
if _CONF['dry_run']:
return 999.9
# ccxt exception is already handled by get_balances
balances = get_balances()
return balances[currency]['free']
balance = balances.get(currency)
if balance is None:
raise TemporaryError(
'Could not get {} balance due to malformed exchange response: {}'.format(
currency, balances))
return balance['free']
@retrier