├── __init__.py ├── .gitignore ├── jupyter_startup.py ├── README.md └── glassnode.py /__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .ipynb_checkpoints/ 2 | __pycache__/ 3 | -------------------------------------------------------------------------------- /jupyter_startup.py: -------------------------------------------------------------------------------- 1 | # Optional startup script when using Jupyter Notebooks 2 | import os 3 | 4 | GLASSNODE_CLIENT_PATH = os.getenv('GLASSNODE_CLIENT_PATH', '/tmp/gn') 5 | 6 | import sys 7 | sys.path.append(GLASSNODE_CLIENT_PATH) 8 | 9 | # surpress warnings 10 | import warnings 11 | warnings.filterwarnings('ignore') 12 | 13 | from glassnode import GlassnodeClient 14 | import matplotlib.pyplot as plt 15 | import pandas as pd 16 | 17 | # instantiate glassnode client 18 | gn = GlassnodeClient() 19 | 20 | # ipython magic 21 | from IPython import get_ipython 22 | ipython = get_ipython() 23 | 24 | if 'ipython' in globals(): 25 | ipython.magic('matplotlib inline') 26 | 27 | plt.style.use('ggplot') 28 | plt.rcParams['figure.figsize'] = (16, 9) 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # glassnode-api-python-client 2 | 3 | NOTE: THIS REPO IS DEPRECATED AND NOT ACTIVELY MAINTAINED BY THE GLASSNODE TEAM. 4 | 5 | Python client library for Glassnode's API – https://docs.glassnode.com/basic-api/api 6 | 7 | ## Quick Start 8 | 9 | ### API Key 10 | 11 | You can get your API from your [Glassnode account](https://studio.glassnode.com/settings/api). 12 | 13 | You can add you API key your environment variables by running: 14 | 15 | `export GLASSNODE_API_KEY=` 16 | 17 | ### Example Usage 18 | 19 | Instantiate the Glassnode client: 20 | 21 | ``` 22 | from glassnode import GlassnodeClient 23 | 24 | gn = GlassnodeClient(api_key='YOUR-KEY') 25 | ``` 26 | 27 | If you added the API key to your environment variables you can leave the `api_key` argument empty. 28 | 29 | #### Fetching a Metric 30 | 31 | To fetch a metric run the client's `get` method: 32 | ``` 33 | sopr = gn.get( 34 | 'https://api.glassnode.com/v1/metrics/indicators/sopr', 35 | a='BTC', 36 | s='2020-01-01', 37 | i='24h' 38 | ) 39 | ``` 40 | 41 | For a complete list of all available metric endpoints endpoints and query parameters please visit [docs.glassnode.com](https://docs.glassnode.com). 42 | 43 | ## Further Information 44 | 45 | * [API documentation](https://docs.glassnode.com/) 46 | * [Overview of metrics and restrictions](https://glassnode.com/metrics) 47 | -------------------------------------------------------------------------------- /glassnode.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | import datetime 4 | import iso8601 5 | import pandas as pd 6 | 7 | class GlassnodeClient: 8 | 9 | def __init__(self): 10 | self._api_key = '' 11 | 12 | @property 13 | def api_key(self): 14 | return self._api_key 15 | 16 | def set_api_key(self, value): 17 | self._api_key = value 18 | 19 | def get(self, url, a='BTC', i='24h', c='native', s=None, u=None): 20 | p = dict() 21 | p['a'] = a 22 | p['i'] = i 23 | p['c'] = c 24 | 25 | if s is not None: 26 | try: 27 | p['s'] = iso8601.parse_date(s).strftime('%s') 28 | except ParseError: 29 | p['s'] = s 30 | 31 | if u is not None: 32 | try: 33 | p['u'] = iso8601.parse_date(u).strftime('%s') 34 | except ParseError: 35 | p['u'] = s 36 | 37 | p['api_key'] = self.api_key 38 | 39 | r = requests.get(url, params=p) 40 | 41 | try: 42 | r.raise_for_status() 43 | except Exception as e: 44 | print(e) 45 | print(r.text) 46 | 47 | try: 48 | df = pd.DataFrame(json.loads(r.text)) 49 | df = df.set_index('t') 50 | df.index = pd.to_datetime(df.index, unit='s') 51 | df = df.sort_index() 52 | s = df.v 53 | s.name = '_'.join(url.split('/')[-2:]) 54 | return s 55 | except Exception as e: 56 | print(e) 57 | --------------------------------------------------------------------------------