Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get Futures Asset Balance Binance

I tried searching for answers, but to no avail.

How do I get the balance of specific asset for a Futures Asset, for example, USDT?

[{'accountAlias': 'xx', 'asset': 'DOT', 'balance': '0.00000000', 'withdrawAvailable': '0.00000000', 'updateTime': 0}, {'accountAlias': 'xx', 'asset': 'BTC', 'balance': '0.00000000', 'withdrawAvailable': '0.00000000', 'updateTime': 0}, {'accountAlias': 'xx', 'asset': 'SOL', 'balance': '0.00000000', 'withdrawAvailable': '0.00000000', 'updateTime': 0}, {'accountAlias': 'xx', 'asset': 'BNB', 'balance': '0.00000000', 'withdrawAvailable': '0.00000000', 'updateTime': 0}, {'accountAlias': 'xx', 'asset': 'ETH', 'balance': '0.00000000', 'withdrawAvailable': '0.00000000', 'updateTime': 0}, {'accountAlias': 'xx', 'asset': 'ADA', 'balance': '0.00000000', 'withdrawAvailable': '0.00000000', 'updateTime': 0}, {'accountAlias': 'xx', 'asset': 'USDT', 'balance': '0.00000000', 'withdrawAvailable': '0.00000000', 'updateTime': 0}, {'accountAlias': 'xx', 'asset': 'XRP', 'balance': '0.00000000', 'withdrawAvailable': '0.00000000', 'updateTime': 0}, {'accountAlias': 'xx', 'asset': 'BUSD', 'balance': '0.00000000', 'withdrawAvailable': '0.00000000', 'updateTime': 0}]

My code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

acc_balance = client.futures_account_balance()
print(acc_balance)
for check_balance in acc_balance["accountAlias"]:
    if check_balance["asset"] == "USDT":
        usdt_balance = check_balance["balance"]

Error:

for check_balance in acc_balance["accountAlias"]:
TypeError: list indices must be integers or slices, not str

What’s the mistake here? Thanks

>Solution :

acc_balance is a list, not a dictionary. You shouldn’t index into it using a string.

Fixing this, we get the following:

for check_balance in acc_balance:
    if check_balance["asset"] == "USDT":
        usdt_balance = check_balance["balance"]
        print(usdt_balance) # Prints 0.0000
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading