-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathglassNode.py
More file actions
65 lines (56 loc) · 1.92 KB
/
glassNode.py
File metadata and controls
65 lines (56 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import requests
import pandas as pd
import time
import numpy as np
# Instructions:
#
# from glassNode import getAPI
#
# getAPI(
# symbol {string},
# dataCat {string},
# dataName {string},
# APIKey [string, optional = ''],
# currency [string, optional = False, use only applicable to data type]
# interval [string, optional = "24h"],
# time_end [int, optional = 0{years}, aka today],
# time_start [optional = 1{years}],
# ) -> list of dates AND values(numpy.array), list of dates(numpy.array), list of values(numpy.array)
#
# example: Illquid supply:
# link: https://api.glassnode.com/v1/metrics/supply/illiquid_sum
# dataCat = "supply"
# dataName = "illiquid_sum"
def getAPI(symbol, dataCat, dataName, APIKey = '', currency = False, interval = "24h", time_end = 0, time_start = 1):
start_date = (time.time() - (time_start * 31536000))
end_date = (time.time() - - (time_end * 31536000))
if currency == False:
data = requests.get('https://api.glassnode.com/v1/metrics/' + dataCat + '/' + dataName,
params = {
'a': symbol,
'api_key': APIKey,
'i': interval,
's':int(start_date),
'u':int(end_date),
},
)
else:
data = requests.get('https://api.glassnode.com/v1/metrics/' + dataCat + '/' + dataName,
params = {
'a': symbol,
'api_key': APIKey,
'i': interval,
's':int(start_date),
'u':int(end_date),
'c':currency,
},
)
if data.status_code != 200: #lel try except doesnt work
print("Unknown Request Error")
return 1
else:
df = pd.read_json(data.text, convert_dates=['t'])
date = np.asarray(df["t"])
value = np.asarray(df.drop("t", inplace=True))
df = np.asarray(df)
return df, date, value