I am trying to write a for loop that goes through the assets
(BTC, EOS) and the available_balance
(0.00087168, 0). The assets
work however I cannot get to the available_balance
. How would I be able to get to it with json.
import json
pairs= '''
({
'ext_code': '',
'rate_limit_status': 118,
'result': {
'BTC': {'available_balance': 0.00087168, 'cum_realised_pnl': 7.288e-05, 'equity': 0.00087168, 'given_cash': 0},
'EOS': {'available_balance': 0, 'cum_realised_pnl': 0, 'equity': 0, 'given_cash': 0}
},
'ret_code': 0,
'ret_msg': 'OK',
'time_now': '1619987733.732306'}
<bravado.requests_client.RequestsResponseAdapter object at 0x000002D6F7FEB808>)
'''
data = json.loads(pairs)
Wallet_balance = data[0]['result']
for assets in balance:
print("Asset: ", assets, " Balance: ", assets['available_balance'])
Expected Output:
Asset: BTC Balance: 0.00087168
Asset: EOS Balance: 0
The pprint Output:
({'ext_code': '',
'ext_info': '',
'rate_limit': 120,
'rate_limit_reset_ms': 1620081183677,
'rate_limit_status': 117,
'result': {'BTC': {'available_balance': 0.00087168,
'cum_realised_pnl': 7.288e-05,
'equity': 0.00087168,
'given_cash': 0,
'occ_closing_fee': 0,
'occ_funding_fee': 0,
'order_margin': 0,
'position_margin': 0,
'realised_pnl': 0,
'service_cash': 0,
'unrealised_pnl': 0,
'used_margin': 0,
'wallet_balance': 0.00087168},
'EOS': {'available_balance': 0,
'cum_realised_pnl': 0,
'equity': 0,
'given_cash': 0,
'occ_closing_fee': 0,
'occ_funding_fee': 0,
'order_margin': 0,
'position_margin': 0,
'realised_pnl': 0,
'service_cash': 0,
'unrealised_pnl': 0,
'used_margin': 0,
'wallet_balance': 0},
'ETH': {'available_balance': 0.03362706,
'cum_realised_pnl': -7.41e-06,
'equity': 0.03362706,
'given_cash': 0,
'occ_closing_fee': 0,
'occ_funding_fee': 0,
'order_margin': 0,
'position_margin': 0,
'realised_pnl': 0,
'service_cash': 0,
'unrealised_pnl': 0,
'used_margin': 0,
'wallet_balance': 0.03362706},
'USDT': {'available_balance': 0,
'cum_realised_pnl': 0,
'equity': 0,
'given_cash': 0,
'occ_closing_fee': 0,
'occ_funding_fee': 0,
'order_margin': 0,
'position_margin': 0,
'realised_pnl': 0,
'service_cash': 0,
'unrealised_pnl': 0,
'used_margin': 0,
'wallet_balance': 0},
'XRP': {'available_balance': 0,
'cum_realised_pnl': 0,
'equity': 0,
'given_cash': 0,
'occ_closing_fee': 0,
'occ_funding_fee': 0,
'order_margin': 0,
'position_margin': 0,
'realised_pnl': 0,
'service_cash': 0,
'unrealised_pnl': 0,
'used_margin': 0,
'wallet_balance': 0}},
'ret_code': 0,
'ret_msg': 'OK',
'time_now': '1620081183.700541'},
<bravado.requests_client.RequestsResponseAdapter object at 0x0000016DC011F888>)
See Question&Answers more detail:os