-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglassnode_client.py
46 lines (36 loc) · 1.04 KB
/
glassnode_client.py
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
import requests
import iso8601
from iso8601 import ParseError
import pandas as pd
class GlassnodeClient:
def __init__(self, api_key):
self.api_key = api_key
def get(self, url, a="BTC", i="24h", c="native", s=None, u=None, in_df=False):
p = dict()
p["a"] = a
p["i"] = i
p["c"] = c
if s is not None:
try:
p["s"] = iso8601.parse_date(s).strftime("%s")
except ParseError:
p["s"] = s
if u is not None:
try:
p["u"] = iso8601.parse_date(u).strftime("%s")
except ParseError:
p["u"] = s
p["api_key"] = self.api_key
r = requests.get(url, params=p)
try:
r.raise_for_status()
except Exception as e:
print(e)
print(r.text)
if not in_df:
return r.json()
try:
df = pd.read_json(r.text, convert_dates=["t"])
return df
except Exception as e:
print(e)