First Step to becoming a Crypto Quant

gamparohit
2 min readFeb 14, 2021

Downloading historical trading data from the leading crypto Exchange

Photo by Pierre Borthiry on Unsplash

The first step to start algorithmic-trading is to download the relevant data about the pair from the exchange. Let us use Binance as it is the largest crypto exchange by volume. Let us use BTC-USDT pair here for reference. The code demonstrated here is a inspiration from here.

We will be using python to get the required data and store them as .csv files.

Firstly, let us import the necessary packages.

Using the Binance API Documentation here, we will create a small function to get the Candlestick/Kline data. Since there is a limit on how much data we can get each time, we will get call this function repeatedly till we get all the data.

Now lets bring it all together, i.e. call the above function sequentially to retrieve all the candlestick data available till data from Binance , and store them in local storage as csv files for future use. For simpler file management, let’s create a folder called binance_data, which would store this script as well as the csv data.

Let us call the functions:

In the line number 4 of the above code we are calling the candle_to_csv function for the pair BTC-USDT in Binance to get all the candlestick data available for the required intervals(size of each candle).

You can add multiple trading pairs just by adding it after line four. Example is shown below.

Run this script periodically to keep updating the data that was collected after the last run of the script.

--

--

gamparohit

Python Programmer interested in Data Science and Algo-Trading