ai-system / backend /router_crypto.py
Evogoatml's picture
fix: backend now regular folder, not submodule
65464fc
raw
history blame contribute delete
565 Bytes
from fastapi import APIRouter
import os, requests
router = APIRouter()
API_KEY = os.getenv("APILAYER_KEY")
@router.get("/price")
def get_price(base: str = "BTC", quote: str = "USD"):
url = f"https://api.apilayer.com/exchangerates_data/latest?base={base}&symbols={quote}"
headers = {"apikey": API_KEY}
r = requests.get(url, headers=headers)
data = r.json()
if "error" in data or not data.get("success"):
return {"error": data.get("error", "API call failed")}
return {"base": base, "quote": quote, "rate": data["rates"].get(quote)}