Using Python 3 to Retrieve Your Cryptocurrency Balances from Binance Part 1

in #binance6 years ago (edited)

In this tutorial we will discuss a simple method for retrieving account balances from Binance using the Binance API. I created this to simplify retrieval because logging into Binance with 2FA is time consuming and frustrating!

Requirements:
Python 3 :
Download here: https://www.python.org/downloads/

Binance API Key and Security Key:
Instructions: https://support.binance.com/hc/en-us/articles/360002502072-How-to-create-API

Binance API: Downloads and Reference:
https://github.com/binance-exchange/binance-official-api-docs

You can create your Python script with any simple text editor such as Notepad (Windows), TextEdit ( Mac OS X), or any number GUI or CL editors for (Linux). Or you can use applications such as JUPYTER or ATOM and others. Other than these tidbits of information this article will not discuss basic concepts of using Python, editors or API’s.

Let’s get started!

Create a folder in your documents folder and call it “BinanceScripts” here you will save all the files you create in this tutorial.

Create a personal.PY file.
The personal.PY file will contain three lines. This file is not meant for sharing with anyone! DO NOT SHARE! The file will contain your API Key and your Secret Key you generated from this site:
https://support.binance.com/hc/en-us/articles/360002502072-How-to-create-API

The reason you must not share these keys is because these keys allow you to execute transactions, check balances, and transfer coins to external wallets programmatically.

Both the API and Secret Keys contain 64 unique alphanumeric characters and will look something like this

Example API Key Structure:
A1oB2oc3A1oB2oc3A1oB2oc3A1oB2oc3A1oB2oc3A1oB2oc3A1oB2oc3A1oB2oc3

Your personal.py file will look like this (Replace “your api and secret keys between the single quotes!) :

***** Begin: personal.py *****
Screen Shot 2018-04-25 at 9.06.56 AM.png
***** End: personal.py ******

Now it's time to create the application that will get our balance for the coin we've selected.

We will import the personal.PY file you created in to the application.
We will import the binance.client function from the Client API
We will store our API_KEY and API_SECRET into a variable called bClient that will grant us access to our balance data.
We will store Binance account asset information from the Binance Exchange in another variable called coin_balance.
Finally we will print out what Binance Exchange has.

Here's the code:

*****Begin: binanceBal.py*****
Screen Shot 2018-04-25 at 9.03.43 AM.png

***** End: binanceBal.py *****

At the command line ( I use a Mac) you will enter:

[your machine name]: binanceScripts [username]$ python3 binanceBal.py

Returned data will look like this where the "free and locked balances" will vary depending on your coin wealth or poverty level. The free balance is what is available to you for any purpose you desire. The locked balance is what is currently in use for a pending trade (sell or buy):

“Coin” “free balance” “locked balance”
BTC 1.05102000 0.00000000

That’s it! I hope this was simple, clear, concise and useful for you.
Part 2 is here
Part 3 is now available

Sort:  

@jagedgem, let me be the first to welcome you to Steemit! Congratulations on making your first post!

I gave you a $.05 vote!

Would you be so kind as to follow me back in return?

Coin Marketplace

STEEM 0.17
TRX 0.13
JST 0.027
BTC 60986.74
ETH 2636.75
USDT 1.00
SBD 2.63