While Coin Metrics Network Data Pro offers users the ability to analyze aggregated on-chain metrics for a variety of cryptoassets, some power users may require additional customization and granularity. Coin Metrics ATLAS search engine equips users with the on-chain analytical toolset they need to workshop their own custom metrics.
Resources
This notebook demonstrates basic functionality offered by the Coin Metrics Python API Client, ATLAS, and Network Data Pro.
Coin Metrics offers a vast assortment of data for hundreds of cryptoassets. The Python API Client allows for easy access to this data using Python without needing to create your own wrappers using requests and other such libraries.
To understand the data that Coin Metrics offers, feel free to peruse the resources below.
The Coin Metrics API v4 website contains the full set of endpoints and data offered by Coin Metrics.
Download the entire notebook as either a jupyter notebook to run yourself or as a pdf from the two links below
Notebook Setup
from os import environimport pandas as pdimport loggingfrom datetime import date, datetime, timedeltafrom coinmetrics.api_client import CoinMetricsClientimport jsonimport loggingimport seaborn as snsimport matplotlib.pyplot as plt%matplotlib inlinefrom IPython.display import Markdown as md
# We recommend privately storing your API key in your local environment.try: api_key = environ["CM_API_KEY"] logging.info("Using API key found in environment")exceptKeyError: api_key ="" logging.info("API key not found. Using community client")client =CoinMetricsClient(api_key)
2024-09-16 14:50:24 INFO Using API key found in environment
Block-by-Block Metrics
With Network Data Pro, block-by-block metrics are offered for both BTC and ETH. With ATLAS, however, we have the ability to retrieve block-by-block metrics for any asset in ATLAS coverage.
In this example, we quantify the total amount of USDC and USDT transferred on a block-by-block basis.
hours =2end = datetime.now()start = end -timedelta(hours=hours)
# Retrieving data for both USDC and USDT (ETH chain)asset_list = ['usdc','usdt_eth']
for asset in asset_list:print('Fetching '+ asset.upper() +' transactions...')# ATLAS 'Get List of Transactions' functionvars()[asset +'_tx'] = client.get_list_of_transactions_v2( asset=asset, start_time=start, end_time=end ).to_dataframe().drop_duplicates(subset=['txid'],keep='last')
# Transform balance updates into block-by-block transfer metrics with one line of codeusdc_tx_bbb = pd.DataFrame(usdc_tx.groupby('height')['amount'].sum())usdc_tx_bbb.head()
ax = sns.lineplot( data=usdc_tx_bbb, y=usdc_tx_bbb['amount'], x=usdc_tx_bbb.index)ax.set_xlabel("Block Height", fontsize =12)ax.set_ylabel("Total Transfer \nAmount", fontsize =12)plt.setp(ax.get_xticklabels(), rotation=45)ax.xaxis.set_ticks(plt.gca().get_xticks())plt.gca().set_xticklabels(['{:.0f}'.format(x) for x in plt.gca().get_xticks()])ax.yaxis.set_ticks(plt.gca().get_yticks())plt.gca().set_yticklabels(['${:,.1f}M'.format(y/1000000) for y in plt.gca().get_yticks()])plt.ylim([usdc_tx_bbb['amount'].min(), usdc_tx_bbb['amount'].max()*1.1])plt.xlim([usdc_tx_bbb.index[0], usdc_tx_bbb.index[-1]])plt.annotate('Source: Coin Metrics ATLAS', xy=(1, -0.195), xycoords='axes fraction', color='black',xytext=(-8, 0), textcoords='offset pixels', horizontalalignment='right', verticalalignment='bottom')ax.set_title('\nUSDC Transactions (Block-by-Block) \n', fontsize =16)plt.show()
md('<br><font size="3.5">Transaction info can also be viewed in the **ATLAS** graphical user interface:<br><br>**Largest Transaction:** <br>https://atlas.coinmetrics.io/transaction-details?asset=usdc&tx_hash=' + str(largest_tx.txid) )
Transaction info can also be viewed in the ATLAS graphical user interface:
Largest Transaction:
https://atlas.coinmetrics.io/transaction-details?asset=usdc&tx_hash=ca9d6c9c2e86a71c5482845abf9a8821d743bd2923fb73cb87177e6e83d86d9e
USDT Transactions
usdt_eth_tx.tail()
# Transform balance updates into block-by-block transfer metrics with one line of codeusdt_tx_bbb = pd.DataFrame(usdt_eth_tx.groupby('height')['amount'].sum())usdt_tx_bbb.head()
ax = sns.lineplot( data=usdt_tx_bbb, y=usdt_tx_bbb['amount'], x=usdt_tx_bbb.index, color='green')ax.set_xlabel("Block Height", fontsize =15)ax.set_ylabel("Total Transfer \nAmount", fontsize =15)plt.setp(ax.get_xticklabels(), rotation=45)ax.xaxis.set_ticks(plt.gca().get_xticks())plt.gca().set_xticklabels(['{:.0f}'.format(x) for x in plt.gca().get_xticks()])ax.yaxis.set_ticks(plt.gca().get_yticks())plt.gca().set_yticklabels(['${:,.1f}M'.format(y/1000000) for y in plt.gca().get_yticks()])plt.ylim([usdt_tx_bbb['amount'].min(), usdt_tx_bbb['amount'].max()*1.1])plt.xlim([usdt_tx_bbb.index[0], usdt_tx_bbb.index[-1]])plt.annotate('Source: Coin Metrics ATLAS', xy=(1, -0.195), xycoords='axes fraction',color='black', xytext=(-8, 6), textcoords='offset pixels', horizontalalignment='right', verticalalignment='bottom')ax.set_title('\nUSDT Transactions (Block-by-Block) \n', fontsize =17);
md('<br><font size="3.5">Transaction info can also be viewed in the **ATLAS** graphical user interface:<br><br>**Largest Transaction:** <br>https://atlas.coinmetrics.io/transaction-details?asset=usdt_eth&tx_hash=' + str(largest_usdt_tx.txid) )
Transaction info can also be viewed in the ATLAS graphical user interface:
Largest Transaction:
https://atlas.coinmetrics.io/transaction-details?asset=usdt_eth&tx_hash=ec6ca03c17cea5c528378bbfa65ef1fb7471395c74a6e89d7344be0932c94a1c
Cross-Asset Metrics
With Network Data Pro, users have the ability to retrieve aggregated daily transfers for specific assets such as USDC and USDT. With ATLAS, however, we have the ability to create more customized, granular metrics.
In this example, we quantify the total size of transactions where USDT and USDC are transferred simultaneously, on a block-by-block basis.
md('<br><font size="3.5">Transaction info can also be viewed in the **ATLAS** graphical user interface:<br><br>**USDC:** <br>https://atlas.coinmetrics.io/transaction-details?asset=usdc&tx_hash=' + str(txhash) + '<br>**USDT:** <br>https://atlas.coinmetrics.io/transaction-details?asset=usdt_eth&tx_hash=' + str(txhash))
Transaction info can also be viewed in the ATLAS graphical user interface:
USDC:
https://atlas.coinmetrics.io/transaction-details?asset=usdc&tx_hash=8bd1605839db7cf700ac524012a09c71cf9add77d0edec1b81a8342285d092db
USDT:
https://atlas.coinmetrics.io/transaction-details?asset=usdt_eth&tx_hash=8bd1605839db7cf700ac524012a09c71cf9add77d0edec1b81a8342285d092db
# Determine total amount of USDT + USDC transferred on a block-by-block basisboth_tx_bbb = pd.DataFrame(merged.groupby('height')['Total Amount'].sum())both_tx_bbb
240 rows × 1 columns
ax = sns.lineplot( data=both_tx_bbb, y=both_tx_bbb['Total Amount'], x=both_tx_bbb.index, color='purple')ax.set_xlabel("Block Height", fontsize =15)ax.set_ylabel("Total Transfer \nAmount", fontsize =15)plt.setp(ax.get_xticklabels(), rotation=45)ax.xaxis.set_ticks(plt.gca().get_xticks())plt.gca().set_xticklabels(['{:.0f}'.format(x) for x in plt.gca().get_xticks()])ax.yaxis.set_ticks(plt.gca().get_yticks())plt.gca().set_yticklabels(['${:,.1f}M'.format(y/1000000) for y in plt.gca().get_yticks()])plt.ylim([both_tx_bbb['Total Amount'].min(), both_tx_bbb['Total Amount'].max()*1.1])plt.xlim([both_tx_bbb.index[0], both_tx_bbb.index[-1]])plt.annotate('Source: Coin Metrics ATLAS', xy=(1, -0.195), xycoords='axes fraction', color='black', xytext=(-8, 6), textcoords='offset pixels', horizontalalignment='right', verticalalignment='bottom')ax.set_title('\nUSDC and USDT\nTransferred in Same Transaction\n', fontsize =17);
Entity-Based Metrics
With ATLAS, we can derived our own metrics based on externally-sourced tagged addresses.
In this example, we leverage our catalog of Uniswap liquidity pool contract addresses to estimate USDC inflows and DEX Supply for major trading pairs.
largest_inflow.txidmd('<br><font size="3.5">Transaction info can also be viewed in the **ATLAS** graphical user interface:<br><br>**Largest Transaction:** <br>https://atlas.coinmetrics.io/transaction-details?asset=usdc&tx_hash=' + str(largest_inflow.txid) )
Transaction info can also be viewed in the ATLAS graphical user interface:
Largest Transaction:
https://atlas.coinmetrics.io/transaction-details?asset=usdc&tx_hash=efdc8d8347d53459d3a581d9700b291cb75311f63289ea0d1859b358d91d8b7f
ax = defi_inflow_sum['change'].plot.area(color='navy')plt.title('\n '+ asset.upper() +' Inflows to Uniswap V3\n',fontdict={'fontsize':23})ax.set_xlabel("\nBlock Height")ax.yaxis.set_ticks(plt.gca().get_yticks())plt.setp(ax.get_xticklabels(), rotation=45)ax.xaxis.set_ticks(plt.gca().get_xticks())plt.gca().set_xticklabels(['{:.0f}'.format(x) for x in plt.gca().get_xticks()])plt.xlim([defi_inflow_sum.index[0], defi_inflow_sum.index[-1]])plt.annotate('Source: Coin Metrics ATLAS', xy=(1, -0.195), xycoords='axes fraction', color='black', xytext=(-8, 6), textcoords='offset pixels', horizontalalignment='right', verticalalignment='bottom')plt.gca().set_yticklabels(['${:,.2f}M'.format(x/1000000) for x in plt.gca().get_yticks()]);