Binance trading bots

Free interactive lessons for building crypto trading bots for Binance exchange. Beginners welcome!

Binance trading bots

Here at Saturn Network we are no strangers to writing trading bots. As we work towards building Radex API we, naturally, look at what other exchanges have produced thus far in order to make our exchange easy to use not only for human traders, but also for bot writers. We have said this before - we firmly believe that the best path towards reducing price volatility in unregulated decentralized markets is massive adoption of trading bots. Trading bots will increase liquidity for human traders and will inevitably exploit market inefficiencies and stabilize the prices.

In this blog post we would like to kickstart a new series that teaches beginners how to work with Binance API. As we move forward, we will start to implement simple trading bots to automate some of your trading, and slowly but surely move towards more sophisticated strategies. All the source code used in these blog posts will be published on our GitHub and on our forum.

Let's get started!

API means Application Programming Interface. You can describe it as the language that other programs can use in order to interact with each other. In this case, Binance API is the language that trading bots should use in order to talk to Binance. While it is possible to use any programming language in order to access Binance API we are going to use the excellent, officially supported javascript library.

You can play with the code in this blog post by modifying the code samples and clicking the green run button.

Ultimately, if you do not plan to write a bot yourself but just want to use existing bots, it would still be helpful to know how these bots are made in order to know the limitations. We will do our best to make the code very easy to read and understand!

Today, let's focus on setting up the infrastructure for our further experiments and getting familiar with binance-api-node package. The best way to learn is to learn by doing something. Today, let's learn to pull data from Binance API and plot some charts.

First, we need to learn how to install the library and interact with it. For read-only APIs, it is actually very simple!

Try running this code snippet.

This code will produce an Object - a javascript way of describing things - that has a bunch of information that Binance provides to coders. This most interesting field for us in this object is the symbols field. If you click on the little dropdown triangle symbol to the left of it you will see all the coins that are traded on Binance.

Congratulations! You have just made your first step towards writing your own trading bot! Wasn't that hard, was it? :)

Now let us try something a bit harder. The first thing you need to do when developing a bot is learn how to pull price information. Let's pick a market and look at the data from the exchange. I am going to use ETCBTC market in my examples. Here is how you can pull historical price data from Binance.

This code pulls last 500 candles from Binance for a given trading pair. A candle is simply an aggregation of trades over some time window. In this case, we are pulling open-close-high-low prices over 6 hour periods. Try running this example and see what it shows us.

What you see when you run this code is machine-readable data in JSON format. While our computers love this data, us humans generally think better when we see a picture. Let us convert this data into a chart using the excellent library.

Luckily for you, plotting is a very common use case, so we have written a little library that automatically converts this Binance candle data into a plot. Now plotting price data becomes a very simple task!

This is much easier to analyze! Try playing with the code snippet above by modifying the code to pull data over different time windows and for different markets.

Congratulations! You have made your first steps towards building a trading bot. You have learned how to programmatically connect to a cryptocurrency exchange and pull data from it. If you are interested, you can learn more about binance-api-node package and try pulling various other data from Binance right in the code blocks of this article. In the next chapter if this series, we will make our first order and get even closer to building a trading bot.

Stay tuned, and Happy Trading!

Related Articles