Check balance via API at Binance — Python
Let’s say you wanna make periodic updates with your balance to your email or even to some telegram group. Or you made some script and before making trade yes is cool to have available balance at your broker in these case Binance.
Binance Python package!
Python-binance is the right package needed for this action. After these there is a straight forward way to grab your balance. Load your API credentials and call client.get_account()
from binance.client import Client
import json
#load api's
with open('...config.json') as json_file:
config = json.load(json_file)
client = Client(config["api"], config["secret"])
info = client.get_account()
After your balance is loaded it will show you, even those tokens that has a 0 balance at your account. That is pretty annoying so for prettify these let’s put data to DataFrame and remove those that has 0 vales.
Advice. Rounding from these case is usless for trading as it won’t work properly. For better rounding please see these.
df = pd.DataFrame(info["balances"])
df["free"] = df["free"].astype(float).round(4)
df = df[df["free"] > 0]
print(df)
Conclusion
These are one of the first steps to do before you make any trades at Binance or any other platform whatsoever with your script. To have balance in your local currency as SUM of all tokens you must multiply tokens by the current rate. After SUM all tokens and you will get value in USD, EUR or whatever you prefer.
Sending email’s with Python I covered here.
Clap! Follow me!
Cheers!!