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

in #binance7 years ago (edited)

This is an expansion of a previous article I wrote on retrieving your balances from binance using PYTHON and the Binance API.

I created this script to simplify data retrieval because logging into Binance with 2FA is sometimes time consuming and/or 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 scripts 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.

This new python script will use three functions standard in PYTHON.

open() - used to open the text file that will contain a list of assets (coins you have on the exchange)

readline() - a function that will read each line of the text file containing the list of assets.

close() - the function used to close the file containing the list of assets when the program is complete.

The While command is used to iterate through the file containing the list of assets.

Let’s get started with this newer and more complete version of binanceBal.py!

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

***** Start : Example personal.py file *******

Screen Shot 2018-04-25 at 9.06.56 AM.png

***** End: Example personal.py file ******

Next let’s create a list of assets we have in Binance funds. Open the text editor of your choice and add one coin symbol to each line of the file. Here is an example of binanceAssets.txt.

****** Start Example: BinanceAssets.txt ******
BTC
ETH
LTC
BCC
TRX
XRP
XMR
XVG
ADA
XLM
SINGLS
NEBL
VIBE
WINGS
RLC
EOS
NEO
SUB
DLT
BNB
BCD
LSK
GAS
RCN
ONT
BCPT
****** END Example: BinanceAssets.txt ******

Save this file as BinanceAssets.txt.

Now all we have to do is teach PYTHON how to go get our balances!

We’ll do the following:
Create a new script and call it BinanceAssets.py.
Import our personal.py information
Import the binance.client
Open the BinanceAssets.txt file we just created
Read a line from the open text file
Retrieve balance information for the asset we just read from the text file
Print the asset name, asset balance, and amount of the asset locked up for pending trades
The script will do this over and over until it reaches the end of the text file at which point it will close BinanceAssets.txt.

***** START BinanceAssets.PY *****
Screen Shot 2018-04-25 at 11.29.34 AM.png

******END BinanceAssets.PY ***

I hope this has been informative and useful for you. If so I’d appreciate an upvote! Thanks.
Part 1 ...Part 3

Sort:  

Congratulations @jagedgem! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You published your First Post
You got a First Vote

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

Upvote this notification to help all Steemit users. Learn why here!

Congratulations @jagedgem! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You made your First Vote

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

Upvote this notification to help all Steemit users. Learn why here!