bybitのtickデータを引っこ抜いてくる
ちょっとカッコ悪いですが
import requests import io import pandas as pd import numpy as np import gzip from datetime import datetime as dt from datetime import timedelta import os import time def download_currency_data(pair, date_range): """ https://public.bybit.com/trading/ :param pair: :param date_range: :return: """ days = 0 dfs = [] while True: try: date = date_range[0] + timedelta(days=days) date = date.strftime("%Y-%m-%d") url = f"https://public.bybit.com/trading/{pair}/{pair}{date}.csv.gz" print(f"url = {url}") data = requests.get(url).content gzip_file = io.BytesIO(data) with gzip.open(gzip_file, 'rt') as f: csv_data = f.read() with open("work.csv", "w") as f: f.write(csv_data) df = pd.read_csv("work.csv") df = df[["timestamp", "size", "price", "trdMatchID"]] df["size"] = df["size"].astype(np.float32) df["price"] = df["price"].astype(np.float32) dfs.append(df) os.remove("work.csv") except Exception as e: print(e) days += 1 if date_range[0] + timedelta(days=days) > date_range[1]: break time.sleep(3) dfs = pd.concat(dfs) os.makedirs("data/bybit", exist_ok=True) dfs.reset_index(drop=True).to_feather(f"data/bybit/{pair}.feather") if __name__ == "__main__": download_currency_data(pair="BTCUSD", date_range=(dt(2019, 10, 1), dt(2021, 11, 20))) download_currency_data(pair="ETHUSD", date_range=(dt(2019, 10, 1), dt(2021, 11, 20)))