Search code examples
pythoncryptocurrencyccxthuobi

Fetch balance from Huobi using ccxt


I'm trying to fetch future account balance on huobi.

This is the code I use:

b = ccxt.huobi({
    "apiKey": "API KEY",
    "secret": "SECRET",
    "options": {
        "defaultType": "future"
    },
})
b.fetch_balance()

When I run it, I get this error:

ccxt.base.errors.ExchangeError: huobi {
"status": "error",
"err_code": 4002,
"err_msg": "The merged cross and isolated margin account for USDT-M futures is unavailable.Please complete the query with linear-swap-api/v3/unified_account_info",
"ts": 1695638305262
}

I tried to read huobi API docs as well as ccxt docs, but didn't find anything useful.

Can you please help me with figuring out what is the problem and how I can solve it?


Solution

  • To make it work you need to switch the account type on exchange.

    It is possible to make with ccxt.

    1. Connect to huobi with ccxt:

    exchange = ccxt.huobi({...api...secret...})

    1. Run:

    exchange.contractPrivatePostLinearSwapApiV3SwapSwitchAccountType({'account_type': 1})