ccxt / ccxt

A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading API with support for more than 100 bitcoin/altcoin exchanges
https://docs.ccxt.com
MIT License
31.91k stars 7.37k forks source link

Kraken fetch_balance() returning None for both 'free' and 'used' when 'total' > 0 #6897

Closed rdeghion closed 4 years ago

rdeghion commented 4 years ago
import ccxt

exchange_id = 'kraken'
exchange_class = getattr(ccxt, exchange_id)
exchange = exchange_class({
    'apiKey': api_key,
    'secret': secret,
    'enableRateLimit': True,
    'rateLimit': 2500, 
    'verbose': False,
    'options': {
        'fetchMinOrderAmounts': False
    }

balances = kraken.fetch_balance()
print(balances)
{'info': {'ZUSD': '26.2985', 'XXBT': '0.0030000000'}, 'USD': {'free': None, 'used': None, 'total': 26.2985}, 'BTC': {'free': None, 'used': None, 'total': 0.003}, 'free': {'USD': None, 'BTC': None}, 'used': {'USD': None, 'BTC': None}, 'total': {'USD': 26.2985, 'BTC': 0.003}}

How can 'free' and 'used' both be None, but there is an amount for 'total'? The documentation shows 'free' + 'used' = 'total', but my balances are showing None + None > 0.

kroitor commented 4 years ago

How can 'free' and 'used' both be None, but there is an amount for 'total'?

Easy, because if the exchange only supplies the total, like Kraken does, we cannot possibly know how much is used and how much is free of the total. Kraken just does not supply enough data from the balance endpoint – and this is considered normal. Some exchanges just don't return enough information to find all values with a single request.

You can verify that by just looking into the info. As the CCXT Manual says, the info contains the response from the exchange as is, untouched. Inside the info you can see that Kraken has returned just one value for each currency. From a single value only the total can be deduced directly from Kraken, thus free and used are unknown = undefined = None = null.

The documentation shows 'free' + 'used' = 'total', but my balances are showing None + None > 0.

None means "value unknown / not available from the exchange". So, the true meaning is X + Y > 0.

Python says if the type of the value is None – you should not do arithmetics with it.

Duplicate issues:

Let us know if that does not answer your question.

kroitor commented 4 years ago

Link to the Manual where the above is explained: https://github.com/ccxt/ccxt/wiki/Manual#balance-inference

rdeghion commented 4 years ago

Thank you. I thought 'free' and 'used' were working for Kraken the other day, but I must have been mistaken. I'm new to this... my mistake