DEV Community

lulzasaur
lulzasaur

Posted on

Build a Trading Card Price Bot in 30 Minutes with the TCGPlayer API

Build a Trading Card Price Bot in 30 Minutes with the TCGPlayer API

If you collect or sell trading cards (Pokemon, Magic: The Gathering, Yu-Gi-Oh), you know prices shift constantly. Here's how to build a simple price-checking bot that texts you when a card drops below your target price.

What We're Building

A Python script that:

  1. Checks card prices via the TCGPlayer Price Data API
  2. Compares them against your watchlist
  3. Sends you a text via Twilio when a price drops

Total time: ~30 minutes.

Step 1: Get Your API Key

Sign up at RapidAPI and subscribe to the free tier (200 requests/month — plenty for a personal price bot checking 5 cards daily).

Step 2: The Price Checker

import requests
import json

RAPIDAPI_KEY = "your-key-here"
RAPIDAPI_HOST = "tcgplayer-price-data.p.rapidapi.com"

def search_card(query, game="pokemon"):
    url = f"https://{RAPIDAPI_HOST}/tcgplayer/search"
    params = {"query": query, "game": game, "limit": 5}
    headers = {
        "x-rapidapi-key": RAPIDAPI_KEY,
        "x-rapidapi-host": RAPIDAPI_HOST
    }
    response = requests.get(url, headers=headers, params=params)
    return response.json()

# Example: Check Charizard prices
results = search_card("charizard ex")
for card in results.get("results", []):
    name = card.get("name", "Unknown")
    price = card.get("marketPrice", "N/A")
    low = card.get("lowestPrice", "N/A")
    print(f"{name}: Market ${price} | Lowest ${low}")
Enter fullscreen mode Exit fullscreen mode

Output:

Charizard ex 199/165: Market $42.50 | Lowest $38.99
Charizard ex 006/165: Market $8.75 | Lowest $7.25
Enter fullscreen mode Exit fullscreen mode

Step 3: The Watchlist

WATCHLIST = [
    {"query": "charizard ex", "game": "pokemon", "target_price": 35.00},
    {"query": "black lotus", "game": "magic", "target_price": 5000.00},
    {"query": "blue-eyes white dragon", "game": "yugioh", "target_price": 15.00},
]

def check_watchlist():
    alerts = []
    for item in WATCHLIST:
        results = search_card(item["query"], item["game"])
        for card in results.get("results", []):
            lowest = card.get("lowestPrice", float("inf"))
            if isinstance(lowest, (int, float)) and lowest <= item["target_price"]:
                alerts.append({
                    "name": card["name"],
                    "price": lowest,
                    "target": item["target_price"]
                })
    return alerts
Enter fullscreen mode Exit fullscreen mode

Step 4: Add Notifications

from twilio.rest import Client

def send_alert(alerts):
    client = Client("TWILIO_SID", "TWILIO_TOKEN")
    body = "Price alerts:\n"
    for a in alerts:
        body += f"  {a['name']}: ${a['price']} (target: ${a['target']})\n"
    client.messages.create(
        body=body,
        from_="+1YOUR_TWILIO_NUMBER",
        to="+1YOUR_PHONE"
    )

# Run it
alerts = check_watchlist()
if alerts:
    send_alert(alerts)
    print(f"Sent {len(alerts)} alerts")
else:
    print("No cards below target price")
Enter fullscreen mode Exit fullscreen mode

Step 5: Schedule It

Add to cron (runs every 6 hours):

0 */6 * * * cd /path/to/bot && python3 price_bot.py
Enter fullscreen mode Exit fullscreen mode

With the free tier's 200 requests/month, you can check 5 cards every 6 hours for a month and still have headroom.

What's Next

  • Add a Discord/Slack webhook instead of Twilio
  • Track price history in a SQLite DB to spot trends
  • Expand to cross-marketplace arbitrage (check the same card on multiple platforms)

The full TCGPlayer API supports all major card games and returns market prices, lowest listings, set info, rarity, and card images. Check out the docs.

Top comments (0)