我目前能够使用python binance v0.7.5中的以下代码成功查询我的保证金账户:
client.get_margin_account()
它返回保证金余额列表和列出交易所所有符号的信息,从最高余额到最低余额:
{'tradeEnabled': True,
'transferEnabled': True,
'borrowEnabled': True,
'marginLevel': '999.00000000',
'totalAssetOfBtc': '0.00000000',
'totalLiabilityOfBtc': '0.00000000',
'totalNetAssetOfBtc': '0.00000000',
'userAssets': [{'asset': 'BTC',
'free': '0.00000000',
'locked': '0.00000000',
'borrowed': '0.00000000',
'interest': '0.00000000',
'netAsset': '0.00000000'},
{'asset': 'ETH',
'free': '0.00000000',
'locked': '0.00000000',
'borrowed': '0.00000000',
'interest': '0.00000000',
'netAsset': '0.00000000'}]}
我可以按如下方式查询特定资产:
client.get_margin_account()['userAssets'][0]['free']
但当我使用此代码时:
client.get_margin_account()['userAssets']['btc']['free']
我得到这个错误:
TypeError: list indices must be integers or slices, not str
如何在不指定索引位置的情况下查询帐户中的特定符号
选项1:使用
next()
:选项2:将userAssets转换为字典:
相关问题 更多 >
编程相关推荐