DEV Community

Ozor
Ozor

Posted on • Originally published at api-catalog-three.vercel.app

Build a Real-Time Crypto Price Tracker in Python (Under 50 Lines)

Ever wanted to track your crypto portfolio from the terminal? Here's how to build one in under 50 lines of Python — with live prices, portfolio valuation, and price alerts.

Setup

You need one thing: an API key. No signup form, no email, no credit card.

curl -X POST https://agent-gateway-kappa.vercel.app/api/keys/create
Enter fullscreen mode Exit fullscreen mode
{"key": "gw_abc123...", "credits": 200}
Enter fullscreen mode Exit fullscreen mode

200 free calls. That's it.

pip install requests
Enter fullscreen mode Exit fullscreen mode

The Tracker

import requests
import time
import json

API = "https://agent-gateway-kappa.vercel.app"
KEY = "gw_your_key_here"  # Replace with your key
HEADERS = {"Authorization": f"Bearer {KEY}"}

# Your portfolio: token -> amount held
PORTFOLIO = {
    "bitcoin": 0.5,
    "ethereum": 2.0,
    "solana": 50,
}

# Price alerts: token -> threshold USD
ALERTS = {
    "bitcoin": {"above": 100000, "below": 50000},
    "ethereum": {"above": 5000, "below": 2000},
}

def get_prices(tokens):
    """Fetch live prices for a list of tokens."""
    ids = ",".join(tokens)
    r = requests.get(
        f"{API}/v1/crypto-feeds/prices?ids={ids}&vs=usd",
        headers=HEADERS
    )
    return r.json()

def check_alerts(prices):
    """Check if any price alerts are triggered."""
    triggered = []
    for token, thresholds in ALERTS.items():
        price = prices.get(token, {}).get("usd", 0)
        if price and price > thresholds.get("above", float("inf")):
            triggered.append(f"🔺 {token.upper()} above ${thresholds['above']:,} (now ${price:,.2f})")
        if price and price < thresholds.get("below", 0):
            triggered.append(f"🔻 {token.upper()} below ${thresholds['below']:,} (now ${price:,.2f})")
    return triggered

def display(prices):
    """Print portfolio summary."""
    total = 0
    print("\n" + "=" * 50)
    print(f"{'Token':<12} {'Price':>12} {'Holdings':>10} {'Value':>12}")
    print("-" * 50)

    for token, amount in PORTFOLIO.items():
        price = prices.get(token, {}).get("usd", 0)
        value = price * amount
        total += value
        print(f"{token:<12} ${price:>11,.2f} {amount:>10.4f} ${value:>11,.2f}")

    print("-" * 50)
    print(f"{'TOTAL':<12} {'':>12} {'':>10} ${total:>11,.2f}")
    print("=" * 50)

    alerts = check_alerts(prices)
    for alert in alerts:
        print(alert)

# Run once
prices = get_prices(list(PORTFOLIO.keys()))
display(prices)
Enter fullscreen mode Exit fullscreen mode

Running It

python tracker.py
Enter fullscreen mode Exit fullscreen mode
==================================================
Token            Price   Holdings        Value
--------------------------------------------------
bitcoin     $ 97,432.00     0.5000  $ 48,716.00
ethereum    $  3,891.00     2.0000  $  7,782.00
solana      $    187.50    50.0000  $  9,375.00
--------------------------------------------------
TOTAL                                $ 65,873.00
==================================================
Enter fullscreen mode Exit fullscreen mode

Add Auto-Refresh

Want it to update every 30 seconds? Add a loop:

while True:
    prices = get_prices(list(PORTFOLIO.keys()))
    print("\033[H\033[J", end="")  # Clear terminal
    display(prices)
    print(f"\nRefreshing in 30s... (Ctrl+C to stop)")
    time.sleep(30)
Enter fullscreen mode Exit fullscreen mode

Add Webhook Alerts

Want to get notified on Discord/Slack when an alert fires?

WEBHOOK_URL = "https://discord.com/api/webhooks/YOUR_WEBHOOK"

def send_alert(message):
    requests.post(WEBHOOK_URL, json={"content": message})

# In your loop:
alerts = check_alerts(prices)
for alert in alerts:
    send_alert(alert)
Enter fullscreen mode Exit fullscreen mode

What Else You Can Do

The same API key gives you access to 39 services. For crypto specifically:

  • /v1/crypto-feeds/prices — live prices for 500+ tokens
  • /v1/onchain-analytics/ — on-chain data and whale tracking
  • /v1/frostbyte-wallet/ — multi-chain wallet operations (9 chains)
  • /v1/defi-trading/ — DEX prices and trading data

Full API catalog: api-catalog-three.vercel.app


The complete tracker is about 45 lines. Extend it with historical data, charting, or Telegram alerts. The API handles the hard part — aggregating data from multiple exchanges and chains into one endpoint.

Top comments (0)