DEV Community

api_builder_01
api_builder_01

Posted on

Using Token Metrics API to Track AI and DeFi Index Performance

If you’re tracking crypto sectors like AI, DeFi, or Real-World Assets, you need more than just token prices—you need index-level intelligence.
Token Metrics API gives you access to AI-curated Smart Indices across themes like:
AI Coins

DeFi Tokens

Meme Coins

RWA (Real-World Assets)

Gaming and more

In this tutorial, we’ll show you how to track these indices using the Token Metrics API and build a simple sector tracker.

🧠 What This Tool Will Do
Fetch live performance data for multiple crypto indices

Show daily, weekly, and monthly ROI for each sector

Display it all in a clean dashboard

Perfect for traders, analysts, or crypto newsletter creators.

🔧 Requirements
Python 3

requests, pandas, streamlit

Token Metrics API key (Advanced plan required)

🔑 Step 1: Get Your API Key
Visit: app.tokenmetrics.com/en/api

Upgrade to Advanced to access /smart-indices

Copy your API key

📊 Step 2: Fetch Smart Index Performance
import requests

def get_index_data(index_id):
url = f"https://api.tokenmetrics.com/smart-indices/{index_id}"
headers = {"x-api-key": "YOUR_API_KEY"}
response = requests.get(url, headers=headers)
return response.json()["data"]
You’ll need to know the index_id for each sector (provided in the documentation or UI).

🖥️ Step 3: Build a Dashboard in Streamlit
import streamlit as st
import pandas as pd

st.title("Crypto Sector Index Tracker")

indices = {
"AI Index": "ai-global-25",
"DeFi Index": "defi-global-25",
"RWA Index": "rwa-global-25",
"Gaming Index": "gaming-global-25"
}

rows = []

for name, idx in indices.items():
data = get_index_data(idx)
rows.append({
"Index": name,
"1D Return": data["returns"]["1d"],
"7D Return": data["returns"]["7d"],
"30D Return": data["returns"]["30d"]
})

df = pd.DataFrame(rows)
st.dataframe(df)

📈 Optional: Add Bar Charts
st.bar_chart(df.set_index("Index")[["1D Return", "7D Return", "30D Return"]])

✅ What You’ve Built
A real-time crypto sector tracker

Insights into AI, DeFi, and more via Smart Indices

A tool to monitor sector rotation and performance shifts

🧭 Next Steps
Add price performance charts for top tokens in each index

Compare index ROI vs. Bitcoin over time

Set alerts when an index outperforms BTC or ETH

Export to a newsletter or embed in your own analytics app

Final Word
Smart investors track narratives, not noise. With Smart Indices from Token Metrics, you can stay ahead of the next rotating trend—AI today, DeFi tomorrow.
Use data that actually drives sector momentum.

Top comments (0)