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
32.42k stars 7.45k forks source link

bitget fetch_balance for subaccounts #23025

Open ShieldTrade opened 1 month ago

ShieldTrade commented 1 month ago

Operating System

windows 10

Programming Languages

No response

CCXT Version

No response

Description

bitget has 2 endpoints for fetchBalance depending on the type of account/sub-account you are querying.

GET /api/v2/spot/account/subaccount-assets GET /api/v2/spot/account/assets

Can I use the ccxt fetchBalance method regardless of the type of account or do I have to specify some parameters ?

thankyou

Code

  
carlosmiei commented 1 month ago

Hello @ShieldTrade,

Right now at bitget we only support these endpoints inside fetchBalance

         * @see https://www.bitget.com/api-doc/spot/account/Get-Account-Assets
         * @see https://www.bitget.com/api-doc/contract/account/Get-Account-List
         * @see https://www.bitget.com/api-doc/margin/cross/account/Get-Cross-Assets
         * @see https://www.bitget.com/api-doc/margin/isolated/account/Get-Isolated-Assets
         * @see https://bitgetlimited.github.io/apidoc/en/margin/#get-cross-assets
         * @see https://bitgetlimited.github.io/apidoc/en/margin/#get-isolated-assets

I will check if it is possible to add the sub-account/assets

in the meantime you can call it directly through privateSpotGetV2SpotAccountSubaccountAssets

ShieldTrade commented 1 month ago

@carlosmiei , Thank you for your answer. I need your expertise and advise on the fetchBalance method.

Generally speaking, for the exchange, I know an account can be: Main/sub with different endpoints like in bitget case. Different type like in bybit

image

I also understand ccxt has unified account types

funding for some exchanges funding and spot are the same account main for some exchanges that allow for subaccounts spot margin future swap lending You can retrieve all the account types by selecting the keys from `exchange.options['accountsByType']

Do I need to retrieve my account type and passing it as a type in params upon calling fetch_balance https://github.com/ccxt/ccxt/issues/22909 or CCXT will handle it?

carlosmiei commented 1 month ago

@ShieldTrade FetchBalance always fetches from the main account. Within the main account will default to the unified wallet but you can change by providing type in params

ShieldTrade commented 1 month ago

Thankyou. I need to write a function that FetchBalance for every type of accounts and I do not know in advance if it is main/sub or unified/not-unified.

If I call fetchAccounts()I only have one field for type and, according to your documents, type can be one of the following:

  1. funding for some exchanges funding and spot are the same account
  2. main for some exchanges that allow for subaccounts
  3. spot
  4. margin
  5. future
  6. swap
  7. lending

When you say "you can change by providing type in params". Do you main I can change from main to sub and from unified to swap? Can type return subaccount instead of main (2.) ? Is there a way to understand if the account is unified using ccxt ? If I have a margin ( not unified) subaccount, how do I fetch its balance ? like in params{type:'sub', type:'swap'}

I am sorry if my questions are stupid but my knowledge of the account type is very limited.

It would be very nice if you can provide an example to FetchBalance for every kind of account or, at least, some guidelines. I think fetching balance is a very common task for ccxt user.