【问题标题】:Binance API get Spot asset balancesBinance API 获取 Spot 资产余额
【发布时间】:2021-10-28 18:46:52
【问题描述】:

我正在尝试从我的 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

那么我如何访问我的资产余额?

提前致谢。

【问题讨论】:

    标签: python-3.x list dictionary nested binance-api-client


    【解决方案1】:

    直接试试get_asset_balance()方法

    client.get_asset_balance(asset='BTC')
    

    或尝试从嵌套字典bal 中提取值,如下所示:

    if "balances" in bal: 
        for b in bal['balances']:
            print(b)
    

    【讨论】:

      猜你喜欢
      • 2020-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-01
      • 2018-01-20
      • 1970-01-01
      • 2022-11-22
      • 1970-01-01
      相关资源
      最近更新 更多