def cm_getmetric(asset, metric, date_start, date_end): # this function grabs the metric for asset within the specified date range, # removes the timezone, sets the date as an index and changes the column name to # the name of the metric # Initialize a reference object, in this case `cm` for the Community API cm = coinmetrics.Community() # grab data from CM - h/t permabull nino data = cmdc.combo_convert( cm.get_asset_data_for_time_range(asset, metric, date_start, date_end)) # remove timezone from date data['date'] = data['date'].dt.tz_convert(None) # rename columns to date and metric output = data.rename(columns={"date": "date", "data": metric}) # purge del data # return output data return output
import pandas as pd import ta import json import math import numpy as np import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText import requests import io from datetime import date import datetime # In[32]: cm = coinmetrics.Community() # In[33]: asset = "eth" # In[34]: available_data_types = cm.get_available_data_types_for_asset(asset) available_data_types # In[35]: #Initiates current time now = datetime.datetime.now() #Converts to a timestamp unit
import pandas as pd import coinmetrics as cm import requests import json import plotly.graph_objs as go import plotly.offline as po import datetime import time import san com = cm.Community() api = '041e6774-857f-4533-83ef-3baf35d1568e' projects = san.get("projects/all") def cm_metric(asset,metric,start_date): asset = asset.lower() data = com.get_asset_metric_data(asset=asset,metrics=metric,start=start_date,end=datetime.datetime.now().strftime("%Y-%m-%d")) df = cm.cm_to_pandas(data) df.index = pd.to_datetime(df.index) return df def gn_AdrActCnt(asset,start_date): start_date = int(time.mktime(datetime.datetime.strptime(start_date, "%Y-%m-%d").timetuple())) url = 'https://api.glassnode.com/v1/metrics/addresses/active_count?a='+ asset + '&s=' + str(start_date) + '&api_key=' + api r = requests.get(url=url) data = json.loads(r.content)
# Import Coinmetrics API from checkonchain.general.__init__ import * import coinmetrics cm = coinmetrics.Community( ) # Initialize a reference object, in this case `cm` for the Community API class Coinmetrics_api: def __init__(self, asset, begin_timestamp, end_timestamp): print('...Fetching Coinmetrics API for ' + asset + '...') # List all available metrics for BTC. self.asset = asset self.begin_timestamp = begin_timestamp self.end_timestamp = end_timestamp self.topcapconst = 35 def collect_data(self): available_data_types = cm.get_available_data_types_for_asset( self.asset) metric_list = str( (','.join(available_data_types))) #setup complete metric list #print(metric_list) asset_data = cm.get_asset_data_for_time_range(self.asset, metric_list, self.begin_timestamp, self.end_timestamp) return asset_data def convert_to_pd(self): asset_data = Coinmetrics_api.collect_data(self) df = coinmetrics.cm_to_pandas(asset_data)