query for balance and get the amount of funds available for trading or funds locked in orders https://bybit-exchange.github.io/docs/v5/spot-margin-normal/account-info https://bybit-exchange.github.io/docs/v5/asset/all-balance https://bybit-exchange.github.io/docs/v5
(self, params={})
| 3495 | return self.safe_balance(result) |
| 3496 | |
| 3497 | def fetch_balance(self, params={}) -> Balances: |
| 3498 | """ |
| 3499 | query for balance and get the amount of funds available for trading or funds locked in orders |
| 3500 | |
| 3501 | https://bybit-exchange.github.io/docs/v5/spot-margin-normal/account-info |
| 3502 | https://bybit-exchange.github.io/docs/v5/asset/all-balance |
| 3503 | https://bybit-exchange.github.io/docs/v5/account/wallet-balance |
| 3504 | |
| 3505 | :param dict [params]: extra parameters specific to the exchange API endpoint |
| 3506 | :param str [params.type]: wallet type, ['spot', 'swap', 'funding'] |
| 3507 | :returns dict: a `balance structure <https://docs.ccxt.com/?id=balance-structure>` |
| 3508 | """ |
| 3509 | self.load_markets() |
| 3510 | request = {} |
| 3511 | enableUnifiedMargin, enableUnifiedAccount = self.is_unified_enabled() |
| 3512 | isUnifiedAccount = (enableUnifiedMargin or enableUnifiedAccount) |
| 3513 | type = None |
| 3514 | # don't use getBybitType here |
| 3515 | type, params = self.handle_market_type_and_params('fetchBalance', None, params) |
| 3516 | subType = None |
| 3517 | subType, params = self.handle_sub_type_and_params('fetchBalance', None, params) |
| 3518 | if (type == 'swap') or (type == 'future'): |
| 3519 | type = subType |
| 3520 | lowercaseRawType = type.lower() if (type is not None) else None |
| 3521 | isSpot = (type == 'spot') |
| 3522 | isLinear = (type == 'linear') |
| 3523 | isInverse = (type == 'inverse') |
| 3524 | isFunding = (lowercaseRawType == 'fund') or (lowercaseRawType == 'funding') |
| 3525 | if isUnifiedAccount: |
| 3526 | unifiedMarginStatus = self.safe_integer(self.options, 'unifiedMarginStatus', 6) |
| 3527 | if unifiedMarginStatus < 5: |
| 3528 | # it's not uta.20 where inverse are unified |
| 3529 | if isInverse: |
| 3530 | type = 'contract' |
| 3531 | else: |
| 3532 | type = 'unified' |
| 3533 | else: |
| 3534 | type = 'unified' # uta.20 where inverse are unified |
| 3535 | else: |
| 3536 | if isLinear or isInverse: |
| 3537 | type = 'contract' |
| 3538 | accountTypes = self.safe_dict(self.options, 'accountsByType', {}) |
| 3539 | unifiedType = self.safe_string_upper(accountTypes, type, type) |
| 3540 | marginMode = None |
| 3541 | marginMode, params = self.handle_margin_mode_and_params('fetchBalance', params) |
| 3542 | response: dict |
| 3543 | if isSpot and (marginMode is not None): |
| 3544 | response = self.privateGetV5SpotCrossMarginTradeAccount(self.extend(request, params)) |
| 3545 | elif isFunding: |
| 3546 | # use self endpoint only we have no other choice |
| 3547 | # because it requires transfer permission |
| 3548 | request['accountType'] = 'FUND' |
| 3549 | response = self.privateGetV5AssetTransferQueryAccountCoinsBalance(self.extend(request, params)) |
| 3550 | else: |
| 3551 | request['accountType'] = unifiedType |
| 3552 | response = self.privateGetV5AccountWalletBalance(self.extend(request, params)) |
| 3553 | # |
| 3554 | # cross |
nothing calls this directly
no test coverage detected