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

Method fetch_balance

python/ccxt/phemex.py:2045–2208  ·  view source on GitHub ↗

query for balance and get the amount of funds available for trading or funds locked in orders https://phemex-docs.github.io/#query-wallets https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#query-account-positions https://phemex-doc

(self, params={})

Source from the content-addressed store, hash-verified

2043 return self.safe_balance(result)
2044
2045 def fetch_balance(self, params={}) -> Balances:
2046 """
2047 query for balance and get the amount of funds available for trading or funds locked in orders
2048
2049 https://phemex-docs.github.io/#query-wallets
2050 https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#query-account-positions
2051 https://phemex-docs.github.io/#query-trading-account-and-positions
2052
2053 :param dict [params]: extra parameters specific to the exchange API endpoint
2054 :param str [params.type]: spot or swap
2055 :param str [params.code]: *swap only* currency code of the balance to query(USD, USDT, etc), default is USDT
2056 :returns dict: a `balance structure <https://docs.ccxt.com/?id=balance-structure>`
2057 """
2058 self.load_markets()
2059 type = None
2060 type, params = self.handle_market_type_and_params('fetchBalance', None, params)
2061 code = self.safe_string(params, 'code')
2062 params = self.omit(params, ['code'])
2063 response: dict
2064 request = {}
2065 if (type != 'spot') and (type != 'swap'):
2066 raise BadRequest(self.id + ' does not support ' + type + ' markets, only spot and swap')
2067 if type == 'swap':
2068 settle = None
2069 settle, params = self.handle_option_and_params(params, 'fetchBalance', 'settle', 'USDT')
2070 if code is not None or settle is not None:
2071 coin = None
2072 if code is not None:
2073 coin = code
2074 else:
2075 coin = settle
2076 currency = self.currency(coin)
2077 request['currency'] = currency['id']
2078 if currency['id'] == 'USDT':
2079 response = self.privateGetGAccountsAccountPositions(self.extend(request, params))
2080 else:
2081 response = self.privateGetAccountsAccountPositions(self.extend(request, params))
2082 else:
2083 currency = self.safe_string(params, 'currency')
2084 if currency is None:
2085 raise ArgumentsRequired(self.id + ' fetchBalance() requires a code parameter or a currency or settle parameter for ' + type + ' type')
2086 response = self.privateGetSpotWallets(self.extend(request, params))
2087 else:
2088 response = self.privateGetSpotWallets(self.extend(request, params))
2089 #
2090 # usdt
2091 # {
2092 # "info": {
2093 # "code": "0",
2094 # "msg": '',
2095 # "data": {
2096 # "account": {
2097 # "userID": "940666",
2098 # "accountId": "9406660003",
2099 # "currency": "USDT",
2100 # "accountBalanceRv": "99.93143972",
2101 # "totalUsedBalanceRv": "0.40456",
2102 # "bonusBalanceRv": "0"

Callers

nothing calls this directly

Calls 14

parse_swap_balanceMethod · 0.95
parse_spot_balanceMethod · 0.95
BadRequestClass · 0.90
ArgumentsRequiredClass · 0.90
safe_stringMethod · 0.80
privateGetSpotWalletsMethod · 0.65
load_marketsMethod · 0.45
omitMethod · 0.45

Tested by

no test coverage detected