fetch_balance method in ccxt won't return all assets

1.9k Views Asked by At

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?

1

There are 1 best solutions below

1
On BEST 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)