|
|
|
|
|
|
|
|
|
import requests
|
|
import json
|
|
import os
|
|
import time
|
|
import datetime
|
|
import pandas as pd
|
|
import numpy as np
|
|
import sqlite3
|
|
|
|
def get_markets():
|
|
url = 'https://api.bitvavo.com/v2/markets'
|
|
response = requests.get(url)
|
|
markets = response.json()
|
|
return markets
|
|
|
|
markets = get_markets()
|
|
markets = pd.DataFrame(markets)
|
|
|
|
markets.to_csv('markets.csv', index=False)
|
|
|
|
|
|
|
|
def get_assets():
|
|
url = 'https://api.bitvavo.com/v2/assets'
|
|
response = requests.get(url)
|
|
assets = response.json()
|
|
return assets
|
|
|
|
assets = get_assets()
|
|
assets = pd.DataFrame(assets)
|
|
|
|
assets.to_csv('assets.csv', index=False)
|
|
|
|
print('Data downloaded and saved to assets.csv and markets.csv')
|
|
|
|
|
|
if not os.path.exists('candles'):
|
|
os.makedirs('candles')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
candles = []
|
|
for market in markets['market']:
|
|
data = pd.read_csv(f'candles/{market}.csv')
|
|
data['market'] = market
|
|
candles.append(data)
|
|
|
|
candles = pd.concat(candles)
|
|
|
|
|
|
candles['time'] = pd.to_datetime(candles['time'], unit='ms')
|
|
|
|
|
|
candles = candles.set_index(['market', 'time'])
|
|
|
|
candles.to_csv('candles.csv')
|
|
|
|
conn = sqlite3.connect('crypto_data.db')
|
|
candles.to_sql('candles', conn, if_exists='replace')
|
|
conn.close()
|
|
|
|
print('Candles data saved to candles.csv and crypto_data.db') |