python-3.x - Binance API 获取 Spot 资产余额
问题描述
我试图从我的 Binance 账户中获取我的 Spot 钱包资产的余额。
我试过的:
bal = client.get_account()
print(bal)
回来:
"makerCommission": 15,
"takerCommission": 15,
"buyerCommission": 0,
"sellerCommission": 0,
"canTrade": true,
"canWithdraw": true,
"canDeposit": true,
"balances": [
{
"asset": "BTC",
"free": "4723846.89208129",
"locked": "0.00000000"
},
{
"asset": "LTC",
"free": "4763368.68006011",
"locked": "0.00000000"
}
]
}
因此,为了达到我尝试的平衡值:
bal = client.get_account()
for i in bal:
if(i == 'balances'):
for e in i:
print(e)
但这返回了这个:
b
a
l
a
n
c
e
s
那么如何访问我的资产余额呢?
提前致谢。
解决方案
直接试试get_asset_balance()
方法
client.get_asset_balance(asset='BTC')
或尝试从嵌套字典中提取值,bal
如下所示:
if "balances" in bal:
for b in bal['balances']:
print(b)
推荐阅读
- python-3.x - python-如何从从 Excel 导入的列表中进行绘图?
- javascript - 如何将当前输入值作为参数传递给绑定?
- react-redux - 如何在 redux 操作中注销值
- c# - 无法从 LINQ 语句调用另一个方法
- angular - 更改组件的可见性并滚动到它在 Angular 中不起作用
- button - Kivy:在kv中设置禁用按钮上的文本颜色
- javascript - chrome:如何执行打印命令
- python - 如何使我的脚本自动更改为目录中的下一个文件?
- c# - 使用 C# MongoDB 查询在数据库集合中查找最近的纬度/经度
- browser - 如何在企业浏览器中打开应用程序?