skka3134

skka3134

email
telegram

Machine Learning and Quantitative Investing: 1. Downloading Data with ccxt

  1. Use WSL
  2. Install python pip venv, pip is used to install packages, venv is used to create virtual environments
sudo apt update
sudo apt upgrade
sudo apt install python3
sudo apt install python3-pip
sudo apt install python3-venv
  1. Create a virtual environment
sudo python3 -m venv bot
  1. Activate the environment
source bot/bin/activate 
  1. Configure vscode
which python

/home/skka3134/folder/bot/bin/python
6. Select the interpreter, ctrl+shift+p, select the environment "bot" created earlier
image
7. Install python extension
image
8. Install ccxt, ccxt encapsulates the APIs of most exchanges worldwide, which we can use to download data and initiate trades

sudo /home/skka3134/folder/bot/bin/python -m pip install ccxt
  1. Instantiate the exchange and cache market data
exchange = ccxt.binance({
    'apiKey': '',
    'secret': '',
    'enableRateLimit': True,
})
exchange.load_markets()
  1. Use exchange.fetch_ohlcv to get candlestick data, where ohlcv represents o (open), h (high), l (low), c (close), v (volume). Set symbol to the cryptocurrency pair you want to query, time_interval to 1 day, and start to the start time
symbol = 'BTC/USDT' 
time_interval = '1d' 
start = exchange.parse8601('2020-01-01T00:00:00') 
data = exchange.fetch_ohlcv(symbol=symbol, timeframe=time_interval,since=start)

image
12. Convert the data format for easy viewing, install pandas

sudo /home/skka3134/folder/bot/bin/python -m pip install pandas
  1. Convert the data using DataFrame, which is a tabular data structure
import pandas as pd
data = pd.DataFrame(data, dtype=float) 
data.columns = ['Time','Open','High','Low','Close','Volume']
data['Time'] = pd.to_datetime(data['Time'], unit='ms') 

image
14. Save the new data

data.to_csv('data.csv')
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.