MCPcopy Create free account
hub / github.com/ccxt/ccxt / fetch_balance

Method fetch_balance

python/ccxt/hyperliquid.py:1054–1151  ·  view source on GitHub ↗

query for balance and get the amount of funds available for trading or funds locked in orders https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/spot#retrieve-a-users-token-balances https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers

(self, params={})

Source from the content-addressed store, hash-verified

1052 return self.safe_string(spotCurrencyMapping, code, code)
1053
1054 def fetch_balance(self, params={}) -> Balances:
1055 """
1056 query for balance and get the amount of funds available for trading or funds locked in orders
1057
1058 https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/spot#retrieve-a-users-token-balances
1059 https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-users-perpetuals-account-summary
1060
1061 :param dict [params]: extra parameters specific to the exchange API endpoint
1062 :param str [params.user]: user address, will default to self.walletAddress if not provided
1063 :param str [params.type]: wallet type, ['spot', 'swap'], defaults to swap
1064 :param str [params.marginMode]: 'cross' or 'isolated', for margin trading, uses self.options.defaultMarginMode if not passed, defaults to None/None/None
1065 :param str [params.dex]: for hip3 markets, the dex name, eg: 'xyz'
1066 :param str [params.subAccountAddress]: sub account user address
1067 :param boolean [params.enableUnifiedMargin]: enable unified margin, CCXT tries to auto-detects self value but you can override it
1068 :returns dict: a `balance structure <https://docs.ccxt.com/?id=balance-structure>`
1069 """
1070 # if user provides a different address in params and does not provide the enableUnifiedMargin we assume we need to request the info again
1071 shouldRefresh = (self.safe_string_2(params, 'user', 'address') is not None) and self.safe_bool(params, 'enableUnifiedMargin') is None
1072 userAddress = None
1073 userAddress, params = self.handle_public_address('fetchBalance', params)
1074 type = None
1075 type, params = self.handle_market_type_and_params('fetchBalance', None, params)
1076 marginMode = None
1077 marginMode, params = self.handle_margin_mode_and_params('fetchBalance', params)
1078 isUnifiedEnabled = None
1079 isUnifiedEnabled, params = self.is_unified_enabled('fetchBalance', userAddress, shouldRefresh, params)
1080 dex = self.safe_string(params, 'dex')
1081 isSpot = ((type == 'spot') or isUnifiedEnabled) and (dex is None)
1082 request = {
1083 'type': 'spotClearinghouseState' if (isSpot) else 'clearinghouseState',
1084 'user': userAddress,
1085 }
1086 response = self.publicPostInfo(self.extend(request, params))
1087 #
1088 # {
1089 # "assetPositions": [],
1090 # "crossMaintenanceMarginUsed": "0.0",
1091 # "crossMarginSummary": {
1092 # "accountValue": "100.0",
1093 # "totalMarginUsed": "0.0",
1094 # "totalNtlPos": "0.0",
1095 # "totalRawUsd": "100.0"
1096 # },
1097 # "marginSummary": {
1098 # "accountValue": "100.0",
1099 # "totalMarginUsed": "0.0",
1100 # "totalNtlPos": "0.0",
1101 # "totalRawUsd": "100.0"
1102 # },
1103 # "time": "1704261007014",
1104 # "withdrawable": "100.0"
1105 # }
1106 # spot
1107 #
1108 # {
1109 # "balances":[
1110 # {
1111 # "coin":"USDC",

Callers

nothing calls this directly

Calls 15

handle_public_addressMethod · 0.95
is_unified_enabledMethod · 0.95
safe_string_2Method · 0.80
safe_boolMethod · 0.80
safe_stringMethod · 0.80
safe_listMethod · 0.80
safe_balanceMethod · 0.80
safe_dictMethod · 0.80
safe_numberMethod · 0.80
safe_integerMethod · 0.80
publicPostInfoMethod · 0.65

Tested by

no test coverage detected