token_terminal

Token Terminal Python API Tutorial

This tutorial aims to be a quick guide to get you started using the Token Terminal API integrated into messari’s python library.

Token Terminal requires an API key for authentication so the first step before getting started is to create an instance of the TokenTerminal class using your API key.

[2]:
from messari.tokenterminal import TokenTerminal
API_KEY = 'YOUR_API_KEY'
tt = TokenTerminal(api_key=API_KEY)

API Structure

The Messari Python client contains a number of functions that wrap all of Token Terminal’s API endpoints. These include:

  • get_project_ids

  • get_all_protocol_data

  • get_protocol_data

  • get_historical_metric_data

Below are a few examples to showcase the functionality and types of data each function generates

Get project ids

This function returns all project ids available in Token Terminal. The function is intended to be used as way to find what protocols the API can provide data for.

[2]:
project_ids = tt.get_project_ids()
print(project_ids)
['0x', '1inch', '88mph', 'aave', 'abracadabra-money', 'alchemix-finance', 'alpha-finance', 'autofarm', 'avalanche', 'axie-infinity', 'babyswap', 'balancer', 'bancor', 'barnbridge', 'basket-dao', 'benqi', 'binance-smart-chain', 'bitcoin', 'cardano', 'centrifuge', 'clipper', 'compound', 'cosmos', 'cream', 'cryptex', 'curve', 'decred', 'dhedge', 'dodo', 'dogecoin', 'dydx', 'ellipsis-finance', 'enzyme-finance', 'erasure-protocol', 'ethereum', 'ethereum-name-service', 'fantom', 'fei-protocol', 'filecoin', 'futureswap', 'harvest-finance', 'hegic', 'helium', 'hurricaneswap', 'idle-finance', 'index-cooperative', 'instadapp', 'integral-protocol', 'karura', 'keeperdao', 'keep-network', 'kusama', 'kyber', 'lido-finance', 'liquity', 'litecoin', 'livepeer', 'loopring', 'makerdao', 'maple-finance', 'mcdex', 'metamask', 'mirror-protocol', 'mstable', 'near-protocol', 'nexus-mutual', 'notional-finance', 'opensea', 'optimism', 'pancakeswap', 'pangolin', 'perpetual-protocol', 'piedao', 'polkadot', 'polygon', 'polymarket', 'pooltogether', 'powerpool', 'quickswap', 'rarible', 'rari-capital', 'reflexer', 'ren', 'ribbon-finance', 'saddle-finance', 'set-protocol', 'siren-markets', 'solana', 'spookyswap', 'stake-dao', 'stellar', 'sushiswap', 'swerve-finance', 'synthetix', 'terra', 'tezos', 'the-graph', 'thorchain', 'tokenlon', 'trader-joe', 'uma', 'uniswap', 'unit-protocol', 'venus', 'vesper-finance', 'visor-finance', 'volmex', 'wakaswap', 'xdai', 'yearn-finance', 'yetiswap', 'yield-yak', 'zcash']

Get all protocol data

The function returns an overview of the latest data for all projects, ranging from metadata such as launch dates, logos, brand colors and Twitter followers to more fundamental metrics such as Revenue, GMV, TVL and P/S ratios.

[3]:
all_protocol_data = tt.get_all_protocol_data()
all_protocol_data
[3]:
0x 1inch 88mph aave abracadabra-money alchemix-finance alpha-finance autofarm avalanche axie-infinity ... venus vesper-finance visor-finance volmex wakaswap xdai yearn-finance yetiswap yield-yak zcash
name 0x 1inch 88mph Aave Abracadabra.money Alchemix Finance Alpha Finance Autofarm Avalanche Axie Infinity ... Venus Vesper Finance Visor Finance Volmex WakaSwap xDai yearn.finance YetiSwap Yield Yak Zcash
symbol ZRX 1INCH MPH AAVE SPELL ALCX ALPHA AUTO AVAX AXS ... XVS VSP VISR WAKA STAKE YFI YTS YAK ZEC
launch_date 2017-08-15 2020-12-23 2019-10-10 2017-11-25 2021-05-28 2021-01-22 2020-05-10 2020-04-23 2020-09-12 2018-01-26 ... 2020-09-14 2020-04-22 2021-01-26 2021-01-01 2021-05-01 2020-06-03 2020-07-17 2021-02-01 2021-02-01 2016-10-28
category_tags DeFi,Exchange DeFi,Exchange DeFi,Lending DeFi,Lending DeFi,Lending Asset Management,DeFi,Lending,Stablecoin DeFi,Lending Asset Management,DeFi Blockchain DeFi,Gaming,NFT ... DeFi,Lending,Stablecoin Asset Management,DeFi Asset Management,DeFi DeFi DeFi,Exchange Blockchain Asset Management,DeFi Exchange Asset Management,DeFi Blockchain
description {'how': 'Market makers offer trades through or... {'how': ' Liquidity providers deposit funds in... {'how': 'Lenders deposit funds into 88mph and ... {'how': 'Lenders deposit funds into Aave and r... {'how': 'Overcollateralized borrowers deposit ... {'how': 'Overcollateralized borrowers deposit ... {'how': 'Lenders (Iron Bank) deposit funds int... {'how': 'Liquidity providers deposit funds int... {'how': 'Validators process transactions and r... {'how': 'Players buy/sell NFTs on the Axie mar... ... {'how': 'Lenders deposit funds into Venus and ... {'how': 'Liquidity providers deposit funds int... {'how': 'Liquidity providers deposit funds int... {'how': 'Liquidity providers deposit collatera... {'how': 'Liquidity providers deposit funds int... {'how': 'Validators process transactions and r... {'how': 'Liquidity providers deposit funds int... {'how': 'Liquidity providers deposit funds int... {'how': 'Users deposit funds into Yield Yak an... {'how': 'Miners process transactions and recei...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
revenue_protocol_365d_trend_change 9.587743 NaN NaN 357.351157 NaN NaN NaN NaN NaN 2223.567062 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
volume_24h 116407588.145301 141814402.258839 576299.55105 296292692.828657 75470966.516945 24275380.16746 23750808.667424 7856976.407302 1788215584.085712 542065060.549579 ... 29954685.01629 881627.605719 587411.44606 NaN NaN NaN 214230966.908269 48017.619236 1027256.064909 413382550.840133
volume_cmgr_30 0.881494 1.150308 0.578248 0.336701 0.480695 0.544683 -0.174711 0.065852 -0.316295 -0.161278 ... -0.085082 0.430404 2.386623 NaN NaN 0.030908 -0.053274 1.81919 -0.687395 0.692857
twitter_followers 242374.0 398617.0 13744.0 346818.0 NaN 49868.0 88468.0 79119.0 NaN NaN ... 133263.0 18889.0 NaN NaN NaN NaN 151785.0 NaN NaN 81548.0
smart_contract_registry {'available': False} {'available': True, 'url': 'https://raw.github... {'available': False} {'available': True, 'url': 'https://raw.github... {'available': False} {'available': False} {'available': False} {'available': False} {'available': False} {'available': False} ... {'available': False} {'available': False} {'available': False} {'available': True, 'url': 'https://raw.github... {'available': False} {'available': False} {'available': False} {'available': False} {'available': True, 'url': 'https://raw.github... {'available': False}

181 rows × 113 columns

Get protocol data

The function returns a time series of the latest data for a given project, ranging from metadata such as Twitter followers to more fundamental metrics such as Revenue, GMV, TVL and P/S ratios.

[6]:
protocols = ['uniswap']
start_date = "2021-10-01"
end_date = "2021-10-10"
protocol_data = tt.get_protocol_data(protocols, start_date=start_date, end_date=end_date)
protocol_data
[6]:
uniswap
project business_type business_line version chain component price market_cap market_cap_circulating market_cap_fully_diluted ... pe pe_circulating ps ps_circulating tvl gmv revenue revenue_supply_side revenue_protocol token_incentives
2021-10-01 Uniswap total total total total None 23.444192 2.344419e+10 1.216002e+10 2.344419e+10 ... None None 15.340730 7.956922 4.562549e+09 1.672296e+09 3.229105e+06 3.229105e+06 0.0 None
2021-10-02 Uniswap total total total total None 25.649286 2.564929e+10 1.327781e+10 2.564929e+10 ... None None 16.993874 8.797179 4.643719e+09 1.257296e+09 2.786595e+06 2.786595e+06 0.0 None
2021-10-03 Uniswap total total total total None 25.649286 2.564929e+10 1.327781e+10 2.564929e+10 ... None None 17.188804 8.898087 4.648515e+09 1.221896e+09 2.624770e+06 2.624770e+06 0.0 None
2021-10-04 Uniswap total total total total None 26.044680 2.604468e+10 1.354416e+10 2.604468e+10 ... None None 17.852846 9.284112 4.613903e+09 1.570555e+09 3.464031e+06 3.464031e+06 0.0 None
2021-10-05 Uniswap total total total total None 25.301983 2.530198e+10 1.318691e+10 2.530198e+10 ... None None 17.498264 9.119764 4.754376e+09 1.413950e+09 3.553829e+06 3.553829e+06 0.0 None
2021-10-06 Uniswap total total total total None 25.681384 2.568138e+10 1.337438e+10 2.568138e+10 ... None None 17.775381 9.257080 4.774576e+09 1.943523e+09 4.138442e+06 4.138442e+06 0.0 None
2021-10-07 Uniswap total total total total None 25.320647 2.532065e+10 1.316125e+10 2.532065e+10 ... None None 17.482794 9.087268 4.774576e+09 1.929270e+09 5.215952e+06 5.215952e+06 0.0 None
2021-10-08 Uniswap total total total total None 25.589763 2.558976e+10 1.329077e+10 2.558976e+10 ... None None 18.279795 9.494129 4.760272e+09 1.447673e+09 3.800945e+06 3.800945e+06 0.0 None
2021-10-09 Uniswap total total total total None 24.716686 2.471669e+10 1.287703e+10 2.471669e+10 ... None None 18.181529 9.472309 4.874226e+09 1.035189e+09 2.963146e+06 2.963146e+06 0.0 None
2021-10-10 Uniswap total total total total None 25.188947 2.518895e+10 1.311264e+10 2.518895e+10 ... None None 18.712864 9.741378 4.788339e+09 1.480371e+09 3.324778e+06 3.324778e+06 0.0 None

10 rows × 22 columns

You can also pass a list of protocols as follows:

[8]:
protocols = ['uniswap', 'compound']
protocols_data = tt.get_protocol_data(protocols, start_date=start_date, end_date=end_date)
protocols_data
[8]:
uniswap ... compound
project business_type business_line version chain component price market_cap market_cap_circulating market_cap_fully_diluted ... pe pe_circulating ps ps_circulating tvl gmv revenue revenue_supply_side revenue_protocol token_incentives
2021-10-01 Uniswap total total total total None 23.444192 2.344419e+10 1.216002e+10 2.344419e+10 ... 72.370975 42.599894 7.992581 4.704691 1.031562e+10 5.589713e+09 956431.991425 859716.305114 96715.686311 0.0
2021-10-02 Uniswap total total total total None 25.649286 2.564929e+10 1.327781e+10 2.564929e+10 ... 76.022019 44.713979 8.369279 4.922571 1.044957e+10 5.593048e+09 935131.217816 839693.562090 95437.655726 0.0
2021-10-03 Uniswap total total total total None 25.649286 2.564929e+10 1.327781e+10 2.564929e+10 ... 79.554273 46.846031 8.748837 5.151808 1.020987e+10 5.620313e+09 818289.770154 731997.307531 86292.462623 0.0
2021-10-04 Uniswap total total total total None 26.044680 2.604468e+10 1.354416e+10 2.604468e+10 ... 80.696157 47.471227 8.878214 5.222798 1.020987e+10 5.595316e+09 802641.065305 717303.131063 85337.934242 0.0
2021-10-05 Uniswap total total total total None 25.301983 2.530198e+10 1.318691e+10 2.530198e+10 ... 75.886507 46.241491 8.349751 5.087926 1.032968e+10 5.558912e+09 787867.672436 704276.012938 83591.659498 0.0
2021-10-06 Uniswap total total total total None 25.681384 2.568138e+10 1.337438e+10 2.568138e+10 ... 76.136568 46.358330 8.360892 5.090812 9.899078e+09 5.373649e+09 862805.591801 774315.222537 88490.369264 0.0
2021-10-07 Uniswap total total total total None 25.320647 2.532065e+10 1.316125e+10 2.532065e+10 ... 76.424631 46.496689 8.389929 5.104427 9.899078e+09 5.485177e+09 887401.478753 796357.996566 91043.482187 0.0
2021-10-08 Uniswap total total total total None 25.589763 2.558976e+10 1.329077e+10 2.558976e+10 ... 80.042976 48.668164 8.794353 5.347190 1.058897e+10 5.493907e+09 839121.611572 750479.917816 88641.693756 0.0
2021-10-09 Uniswap total total total total None 24.716686 2.471669e+10 1.287703e+10 2.471669e+10 ... 80.566683 48.871986 8.843268 5.364352 1.045710e+10 5.376628e+09 712359.128314 634413.770030 77945.358284 0.0
2021-10-10 Uniswap total total total total None 25.188947 2.518895e+10 1.311264e+10 2.518895e+10 ... 86.070136 52.387065 9.435111 5.742733 1.020492e+10 5.410650e+09 703203.795413 625171.005537 78032.789876 0.0

10 rows × 44 columns

Now you can access data for both Uniswap or Compound by indexing based on the protocol of interest

[14]:
protocols_data['compound']
[14]:
project business_type business_line version chain component price market_cap market_cap_circulating market_cap_fully_diluted ... pe pe_circulating ps ps_circulating tvl gmv revenue revenue_supply_side revenue_protocol token_incentives
2021-10-01 Compound total total total total None 312.132300 3.121323e+09 1.837312e+09 3.121323e+09 ... 72.370975 42.599894 7.992581 4.704691 1.031562e+10 5.589713e+09 956431.991425 859716.305114 96715.686311 0.0
2021-10-02 Compound total total total total None 326.360290 3.263603e+09 1.919558e+09 3.263603e+09 ... 76.022019 44.713979 8.369279 4.922571 1.044957e+10 5.593048e+09 935131.217816 839693.562090 95437.655726 0.0
2021-10-03 Compound total total total total None 338.139169 3.381392e+09 1.991154e+09 3.381392e+09 ... 79.554273 46.846031 8.748837 5.151808 1.020987e+10 5.620313e+09 818289.770154 731997.307531 86292.462623 0.0
2021-10-04 Compound total total total total None 338.139169 3.381392e+09 1.989175e+09 3.381392e+09 ... 80.696157 47.471227 8.878214 5.222798 1.020987e+10 5.595316e+09 802641.065305 717303.131063 85337.934242 0.0
2021-10-05 Compound total total total total None 313.218627 3.132186e+09 1.908600e+09 3.132186e+09 ... 75.886507 46.241491 8.349751 5.087926 1.032968e+10 5.558912e+09 787867.672436 704276.012938 83591.659498 0.0
2021-10-06 Compound total total total total None 310.492858 3.104929e+09 1.890541e+09 3.104929e+09 ... 76.136568 46.358330 8.360892 5.090812 9.899078e+09 5.373649e+09 862805.591801 774315.222537 88490.369264 0.0
2021-10-07 Compound total total total total None 307.038537 3.070385e+09 1.868020e+09 3.070385e+09 ... 76.424631 46.496689 8.389929 5.104427 9.899078e+09 5.485177e+09 887401.478753 796357.996566 91043.482187 0.0
2021-10-08 Compound total total total total None 315.985263 3.159853e+09 1.921271e+09 3.159853e+09 ... 80.042976 48.668164 8.794353 5.347190 1.058897e+10 5.493907e+09 839121.611572 750479.917816 88641.693756 0.0
2021-10-09 Compound total total total total None 313.563870 3.135639e+09 1.902088e+09 3.135639e+09 ... 80.566683 48.871986 8.843268 5.364352 1.045710e+10 5.376628e+09 712359.128314 634413.770030 77945.358284 0.0
2021-10-10 Compound total total total total None 331.075737 3.310757e+09 2.015111e+09 3.310757e+09 ... 86.070136 52.387065 9.435111 5.742733 1.020492e+10 5.410650e+09 703203.795413 625171.005537 78032.789876 0.0

10 rows × 22 columns

Get historical metric data

This function returns the time series of a specified metric for a given list of projects.

Available metrics include:
- price - market_cap - market_cap_circulating - market_cap_fully_diluted - volume - vol_mc - pe - ps - tvl - gmv - revenue - revenue_supply_side - revenue_protocol - token_incentives
[15]:
metric =  "market_cap"
historical_mktcap = tt.get_historical_metric_data(protocols, metric=metric,
                                                  start_date=start_date, end_date=end_date)
historical_mktcap
[15]:
uniswap compound
2021-10-01 2.344419e+10 3.121323e+09
2021-10-02 2.564929e+10 3.263603e+09
2021-10-03 2.564929e+10 3.381392e+09
2021-10-04 2.604468e+10 3.381392e+09
2021-10-05 2.530198e+10 3.132186e+09
2021-10-06 2.568138e+10 3.104929e+09
2021-10-07 2.532065e+10 3.070385e+09
2021-10-08 2.558976e+10 3.159853e+09
2021-10-09 2.471669e+10 3.135639e+09
2021-10-10 2.518895e+10 3.310757e+09