Created
March 10, 2020 22:16
-
-
Save kadereub/28e82f5c96d81574a53042fbf625995a to your computer and use it in GitHub Desktop.
Read in tick data sourced from the `bitcoincharts` api.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Step 1: Download zip file for bitstampUSD | |
##### Link: -> http://api.bitcoincharts.com/v1/csv/ | |
##### See SO post for more detail: https://stackoverflow.com/questions/16143266/get-bitcoin-historical-data | |
# Step 2: Extract CSV file and save in downloads | |
# Step 3: Run the below code reading and cleaning the data to save as minute ohlc data... | |
import os | |
import numpy as np | |
import pandas as pd | |
downloads_path = os.path.expanduser('~/Downloads') | |
btc_data = pd.read_csv(os.path.join(downloads_path, "bitstampUSD.csv"), header=None) | |
btc_data.columns = ["TimeStamp", "Price", "Volume"] | |
# Convert unix timestamp to datetime | |
btc_data['TimeStamp'] = pd.to_datetime(btc_data['TimeStamp'], unit='s') | |
btc_data.set_index("TimeStamp", inplace=True) | |
# Filter out Older data | |
btc_data.loc[btc_data.index >= "2017-04-01"] | |
btc_data.head(3) | |
ohlc_data = pd.DataFrame() | |
# Group by minute and get OHLC -> Warning takes a while to run for the full dataset | |
grp_btc_data = btc_data.groupby(pd.Grouper(freq='min')) | |
ohlc_data["volume"] = grp_btc_data["Volume"].sum() | |
ohlc_data["open"] = grp_btc_data["Price"].nth(0) | |
ohlc_data["high"] = grp_btc_data["Price"].max() | |
ohlc_data["low"] = grp_btc_data["Price"].min() | |
ohlc_data["close"] = grp_btc_data["Price"].nth(-1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment