How to build a Crypto Trading Bot Tutorial Part 2: Python-binance, API Keys and Connecting to the Binance Exchange

This is the second article in a series designed to help you build a crypto trading bot from scratch, with no prior knowledge of Python. So yes, you will be picking up Python in the process. In this article we will look at installing Python-binance through pip, generating Binance API keys and connecting to the Binance Exchange using Python. 

If at any point you feel that you’re missing a key piece of the puzzle, including but not limited to: how to install python, what is Pip, what is an IDE and how to install one, make sure to check out part one here.

This tutorial is also available as a video guide if you prefer, otherwise just keep on reading:


How to Generate Binance API Keys

Naturally, the first thing you will need is a Binance account. So if you don’t have one, or you’d rather set up yout bot on a seperate account, go ahead and create one here. You can use my referral link to get 5% off your trading fees. Now let’s generate some API keys.

To get your mainnet keys, navigate over your account, and click on API management. Side note: Mainnet are your live API keys, the ones that give access to live trading. You can also generate testnet keys for testing purposes, but in this guide we’ll cover mainnet keys.

On the API management page, give your API a label (any label works) and click Create API

Once your key and secret have been generated make sure to save these, as you will only be shown the secret once. You’ll need to regenerate your keys if you haven’t saved the secret. Now make sure to save your Binance API Key and API Secret. You will only be able to see these at creation, and if you don’t save them you will need to re-generate your keys.

Make sure to give your API Keys the correct permissions. In this case: Enable Reading and Enable Spot & Margin Trading. For security purposes, DO NOT enable Withdrawals. For added security, you can limit the IP range to your IP address so that, even if your API keys are leaked – your account is still safe.

Installing the Python-Binance library with pip

The python-binance library is an open source project that was created to simplify the interaction between Python and the Binance api. You can install this module by running the following command in your cmd / terminal

Connect to the Binance API with Python

Now fire up your IDE and let’s algorithmically connect to the Binance Exchange using Python and the python-binance module. In order to check that we’ve managed go successfully create API keys and connect to the exchange, we will ask Binance to return to us the total value of USDT in our account

An that’s it! You’re now connected to the Binance Exchange using Python. In the next article we will take this further by Learning how to create a basic DCA crypto trading bot, and how to place buy and sell orders.

Did you enjoy this article?

The floating “Subscribe” button is your friend. This button will enable you to receive the latest Cryptomaton guides and articles straight to your inbox.
It will also give you the option to sponsor this site’s content and support the open source resources that it provides. You’ll also get access to premium discord channels in return.

Don’t forget to share this article with your friends, family and/or your wife’s boyfriend. Or you can just subscribe to the mailing list below.

Leave a Reply

Your email address will not be published. Required fields are marked *