- Use WSL
- 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
- Create a virtual environment
sudo python3 -m venv bot
- Activate the environment
source bot/bin/activate
- Configure vscode
which python
/home/skka3134/folder/bot/bin/python
6. Select the interpreter, ctrl+shift+p, select the environment "bot" created earlier
7. Install python extension
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
- Instantiate the exchange and cache market data
exchange = ccxt.binance({
'apiKey': '',
'secret': '',
'enableRateLimit': True,
})
exchange.load_markets()
- 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)
12. Convert the data format for easy viewing, install pandas
sudo /home/skka3134/folder/bot/bin/python -m pip install pandas
- 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')
14. Save the new data
data.to_csv('data.csv')