How to build a basic crypto trading bot in Python – Binance DCA Bot example

In this article we’re going to build upon some of the concepts explained in previous articles, designed to help you understand how to build a crypto trading bot in Python from scratch. This series of articles should also serve as a practical course into learning Python, as you will be picking up core concepts required in programming.

So if throughout this article, you feel like you’re lacking some more basic concepts, then check out the other articles in the series: how to build a crypto trading bot from scratch. This includes the basic foundation of how to install Python, pip and an IDE on your machine as well as how to generate Binance API keys. If you’re completely new to programming that’s where you want to start.

What is a crypto trading bot?

A Trading bot, or trading algorithm is essentially a piece of software that trades cryptocurrency automatically, on your behalf. Under the hood, there are a number of instructions, or rules which tell the program how to behave:  when to buy, when to sell, when to hold etc. A trading bot should be able to streamline and improve upon a manual strategy, or at the very least – automate it.

So let’s start by building very simple DCA bot that will automatically DCA for us on Binance once a week.

Building a DCA crypto trading bot from scratch

Let’s start by installing the correct python libraries using pip:

Now open your IDE and create a new python file. We will import the above libraries into our file and define the variables for our API key and secret, like so:

The next thing we want to do is to create a simple function that will buy 0.0014 worth of BTC:

Now let’s add a main function that calls the above function in a loop, but with a 1 week delay between each loop, so that we can DCA once a week.

If we run this script, it will buy 0.0014 worth of BTC at once launched, and then every week from that moment. So technically, our work here is done. 

But there are some quality of life improvements that we can make to the script in case we want to scale this application up in the future and add more complex logic to it.

So let’s get rid of all hardcoded values and replaces them with variables. What we end up is the following:

Note how on lines 14-18 we have added the coin, quantity, pairing and frequency variables. Now because we have these values stored as variables, all we need to do is play around with those config options to completely change the behaviour of our script. changing coin  to be “ETH” would DCA ETH instead of BTC, and changing the pairing, would modify the base currency.

That’s it. Make sure you subscribe as we will be developing this bot in future articles.

Watch the video as I go into even more detail on the above codebase:

 

Did you enjoy this article? Here’s what to do next…

Become a subscriber by clicking the Button in the bottom right corner. You’ll receive more guides, articles and tools via e-mail. All free of course.

But if you value this blog and its educational resources, you can subscribe to become a paid member for only $3 a month. This will help keep the website open and free.

If  you’re looking for a custom-built cryptocurrency trading algorithm, shoot me a message and let’s talk.

One thought on “How to build a basic crypto trading bot in Python – Binance DCA Bot example

  1. The last seven years of watching the evolution of the crypto currency have been exciting, enlightening and even occasionally amusing, but also somewhat difficult to know how to make profit. While there were certainly many things that happened during that time, many people still don’t fully understand how people make quick return on investment (ROI) in crypto. That being said, I put together a quick review of a bitcoin mining expert, to get you started on the journey towards making quick profit on bitcoin with the help of his mining. (minerrobbertt @ g mailcom) is one of many insightful miners from around the world that’s designed to help people make more money in the new digital currency an inside view of how it works. While not the only publication that covers this topic, it is undoubtedly one of the most popular. This quick guide will help you get a full grasp of the subject and use it to your advantage as you set out to make your money go even further

Leave a Reply

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