Your python client lib has problems. First up the api_key param in your example doesn't work:
`from glassnode import GlassnodeClient
gn = GlassnodeClient(api_key='YOUR-KEY')`
Obviously that's insecure but I wanted to give it a first run and got this:
TypeError: init() got an unexpected keyword argument 'api_key'
Looking at the source I can see why. Anyway, I removed the param as I had set an env variable in PyCharm as well as in OS X:
import os
from glassnode import GlassnodeClient
GLASSNODE_API_KEY = os.getenv('GLASSNODE_API_KEY')
print(GLASSNODE_API_KEY)
gn = GlassnodeClient()
response = gn.get(
'https://api.glassnode.com/v1/metrics/indicators/net_realized_profit_loss?a=BTC&s=1479573422&u=1614470400',
a='BTC',
s='2020-01-01',
i='24h'
)
print(response)
After running it like that I get another error:
401 Client Error: Unauthorized for url: https://api.glassnode.com/v1/metrics/indicators/net_realized_profit_loss?a=BTC&s=1479573422&u=1614470400&a=BTC&i=24h&c=native&s=1577833200&api_key=
<html>
<head><title>401 Authorization Required</title></head>
<body>
<center><h1>401 Authorization Required</h1></center>
<hr><center>nginx/1.15.9</center>
</body>
</html>
Expecting value: line 1 column 1 (char 0)
None
So either it's not picking up the key or something else is going on.
Finally there seem to be an unresolved ParseError reference in glassnode.py. It's clearly the iso8601 ParseError and I've fixed it by making it verbose by adding the module name ahead of ParseError. I've also removed superfluous imports:
import json
import requests
import iso8601
import pandas as pd
class GlassnodeClient:
def __init__(self):
self._api_key = ''
@property
def api_key(self):
return self._api_key
def set_api_key(self, value):
self._api_key = value
def get(self, url, a='BTC', i='24h', c='native', s=None, u=None):
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 iso8601.ParseError:
p['s'] = s
if u is not None:
try:
p['u'] = iso8601.parse_date(u).strftime('%s')
except iso8601.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)
try:
df = pd.DataFrame(json.loads(r.text))
df = df.set_index('t')
df.index = pd.to_datetime(df.index, unit='s')
df = df.sort_index()
s = df.v
s.name = '_'.join(url.split('/')[-2:])
return s
except Exception as e:
print(e)
I run python 3.9 on OS X.
Any pointers would be appreciated.