Skip to content
Advertisement

fetch_balance method in ccxt won’t return all assets

As I call the fetch_balance method from kucoinfutures in ccxt, it only returns BTC, not any other assets. Shouldn’t there be other assets like USDT or ETH too?

Here’s the python code:

exchange = ccxt.kucoinfutures(
    {
        'apiKey': API_KEY,
        'secret': API_SECRET,
        'password': API_PHRASE
    }
)

exchange.verbose = True
balance = exchange.fetch_balance()
print(balance)

Here’s what I get from print(balance):

{'info': {'code': '200000', 'data': {'accountEquity': 0, 'unrealisedPNL': 0, 'marginBalance': 0, 'positionMargin': 0, 'orderMargin': 0, 'frozenFunds': 0, 'availableBalance': 0, 'currency': 'XBT'}}, 'timestamp': None, 'datetime': None, 'BTC': {'free': 0.0, 'used': 0.0, 'total': 0.0}, 'free': {'BTC': 0.0}, 'used': {'BTC': 0.0}, 'total': {'BTC': 0.0}}

Am I missing something?

Advertisement

Answer

It seems like fetchBalance only returns one currency at a time. To get USDT as the asset to be returned, you must pass the param currency via params currently using the exchange-specific currency id.

import ccxt

exchange = ccxt.kucoinfutures( ... )
exchange.load_markets()

currency = exchange.currency('USDT')
balance = exchange.fetch_balance({'currency': currency['id']})
print(balance)
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement