Have you noticed how many new coins tend to skyrocket temporarily the moment they are added to the Binance Exchange? Wouldn’t it be great if you could take advantage of that initial pump? This Binance Trading bot that I’ve been working on aims to do just that. The bot scans the Binance exchance and buys a coin as soon as it’s been listed on Binance.
It’s fresh out of the oven so I’m pretty excited to see how it performs, and it comes with all the bells and whistles: from trailing stop loss to test mode and more.
This open source crypto trading algorithm had multiple updates in the past couple of months. Catch up on the latest in the video below.
- A Binance account (obviously)
- Some python skills
- A bit of time
Making a start
First things first, if you don’t have a Binance account, or would like to create a separate account to run the bot on, go ahead and create one here . You can use my referral link to get 5% off your trading fees. With a Binance account created, we’re going to Generate some API Keys.
To get your mainnet keys, navigate over your account, and click on API management.
On the API management page, give a label to your API key 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 let’s give it the permissions that we require to run the bot on it. We’re only going to do Spot trading, so we only need to select Enable Reading and Enable Spot & Margin Trading.
Coding the crypto trading bot
First of all, I’ve open sourced the code and it’s available on GitHub, if you would like to have a look yourself or simply download the source. Keep on reading to understand how it works.
The easiest way to do so is to launch your cmd/terminal and run the following commands using pip. Note that on Macs you may have to use pip3 instead.
Naturally, you need to have pip and python already installed on your machine.
Create credentials file
Create a directory called auth and inside this directory create a new .yml file called auth.yml. Inside the file,, duplicate the exact format below and replace the dummy text with your Binance actual key and secret. The crypto trading bot will need those in order to place trade on the Binance exchange.
Create an authentication file
In the same directory, go ahead and create a new file called binance_auth.py we’re going to use this file to connect to the Binance client via the Binance API.
Create a config file
This is the file that tells our trading bot what to do, and how to trade. We’re going to create a few configurable options so that we can optimise our strategy. In the main directory (a level up from the auth directory) create a config.yml file like so:
Have a look at the comments for more details regarding each config option.
Let’s create a file that will help us load the configuration that we just created and call it load_config.py
In order to be able to keep track of our orders and order details such as the price, time, volume and symbol, every trade we make must be logged in a local file. Your live trades will appear on the Binance reports, but test trades won’t, so a local file is the best way to keep track of test mode gains and losses. Go ahead and create a store_order.py file in the main directory The functions below will help us load and store both test and live trades.
if you’re enjoying this content please sign up below for more
Create a trade client
The purpose of this file is to help perform two important operation for our crypto trading bot. Therefore it contains two functions that will be called in the main file. The first function will convert the volume of our paired coin to that of the coin we’re about to buy. If you remember the configuration options under the config file, you’ll recall an option called PAIRING. This tells our trading bot what to pair the base asset with. For example if pairing is set to USDT the bot will only place trades on coinUSDT (ie: BTCUSDT).
The first function ensures that the volume of the trade in USDT is converted to its equivalent in the base asset. For example 15USDT would convert to around 0.000330 BTC – and this is the value that Binance needs to know in order to automatically place a trade for us.
The second function creates an order request with the symbol-pair, volume and side (BUY or SELL).
In the main directory, create a file called trade_client.py and define the two functions like so:
The reason our conversion function looks a little more complex than you would probably expect is because Binance is quite particular with the format of the volume order. For example, while BTCUSDT can have an accuracy of up to 6 decimal points, many other coins have different step-sizes. For instance the accuracy for a XRPUSDT trade is only 1 decimal point (ie: 1.1). Sending a request on XRPUSDT with any other format (1.1000) would return an error.
Coding the crypto trading bot logic
This is it, now that we have all the necessary infrastructure it’s time to write the buy and sell logic, and execute it.
Inside our main directory we’re going to create a main.py file. The first step is to import all the files we’ve created and any other dependencies. and define our Binance client like so:
Next, we’re going to write two functions. One that will return a list of all the tradeable coins on Binance, and a second functions that will return the list once again and also compare any differences between the two lists. If new coins are found in the second list, we’ll return those too.
Ok now we need a function for our trading bot to return us the latest price for a coin on Binance.
At this point we have all the necessary functions to buy, sell, perform logic trades and store any trade data that we want locally. All that’s left now is to bring all this together in a logical manner and execute the script.
We’re going to define a main() function, where we’re going to start by performing sell checks, and the moving into buy checks. This last block of code is significantly longer than what we’ve seen above, so spend some time and study the comments and logic behind it.
And there you have it, you should now be able to buy new coins just as they are being listed on the Binance exchange with this neat crypto trading bot. Good luck!