Coding a Binance Trading Bot that detects new coins the moment they are listed

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.

Requirements

  • 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. 

Install dependencies

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.

Load Config

Let’s create a file that will help us load the configuration that we just created and call it load_config.py

Store orders

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!

Did you enjoy this article? Sign up below for more awesome content!

If you found this article useful, please consider buying me a coffee here, or donating via the Brave browser. Thanks!

20 thoughts on “Coding a Binance Trading Bot that detects new coins the moment they are listed

  1. What do I actually run? main.py?

    If I do that it seems to work but this is the status that I got after a while:

    New coins detected: [{‘symbol’: ‘FORUSDT’, ‘price’: ‘0.12880000’}, {‘symbol’: ‘REQUSDT’, ‘price’: ‘0.40160000’}, {‘symbol’: ‘GHSTUSDT’, ‘price’: ‘2.35000000’}, {‘symbol’: ‘TRURUB’, ‘price’: ‘50.00000000’}, {‘symbol’: ‘FISBRL’, ‘price’: ‘11.93000000’}]
    New coin[‘symbol’] detected, but FORUSDT is currently in portfolio
    New coin[‘symbol’] detected, but REQUSDT is currently in portfolio
    New coin[‘symbol’] detected, but GHSTUSDT is currently in portfolio
    New coin[‘symbol’] detected, but TRURUB is currently in portfolio
    New coin[‘symbol’] detected, but FISBRL is currently in portfolio

    There also does not appear to be a log, for example trades.txt as in the volatility trader.

  2. Once I have installed python with pip, I just press the main.py file (after putting in my personal API and Secret key in Binance_auth file) while Binance is logged in on the browser yeah?

  3. Hey thanks for the code. After configuration I was running the main.py in test mode, however it just says working… What should be the outcome when I am running it in testmode?

  4. Hi,

    Thanks for your work, i just started the script, let’s see what happens..

    If i may offer 2 suggestions for your guide:

    1. Maybe add an explanation on how to actually run the script, i am not familiar with python and didn’t really know how to do it. I used “python main.py”, it should be correct..

    2. In the auth.yml file, i didn’t touch the “binance_tld” line since you didn’t mention it in the guide and well, it suprisingly didn’t work:p Maybe add that you are supposed to add “com” in the guide or a comment in the code.

    Thanks again,
    John

  5. Have this up and looks to be working well, just sitting patiently for any new listings! Will let you know how it does when that happens.

    Question, in the “fix order issues and cascading API crash” commit from a few days ago, you reset the TP to equal SL and TSL to equal TTP in the config.yml- do you mind explaining the reasoning?

    Cheers!

    1. Hey, the config.yml is more of an example of how to customize the strategy. You should input your own values in for better results. As for the API crash, still looking into why that is

  6. I keep getting this error when trying to run it: Failed to establish a new connection: [Errno 11001] getaddrinfo failed

    Any idea why?

  7. Hi,
    Nice job and idea.
    I have a suggestion for you that I think it may help:
    Have you consider not to r/w the order’s file and keep it in memory to improve time?
    And maybe even remove the print statements?

  8. Hi,
    Nice job and idea.
    Have you considered, in order to improve the speed, not to r/w the orders in a file but keep them in memory?
    Maybe even not doing the print statements could help?!

    1. Thanks. I’ve actually updated the script so now it runs at the minimum interval supported by Binance that won’t result in a temp IP ban – 0.1s per iteration

  9. File \site-packages\requests\adapters.py”, line 516, in send
    raise ConnectionError(e, request=request)
    requests.exceptions.ConnectionError: HTTPSConnectionPool(host=’api.binance.binance_tld’, port=443): Max retries exceeded with url: /api/v3/ping (Caused by NewConnectionError(‘: Failed to establish a new connection: [Errno 11001] getaddrinfo failed’))

    What can cause this?

    Thank you.

  10. Hi there, thank you for this guide! I have a question about when you run this bot. Do you run it 5 mins before the coin is listed? 10 mins before? Does Binance automatically log you out after a certain amount of time?

Leave a Reply

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