CryptoSentinel_AI / app /price_fetcher.py
mgbam's picture
Create app/price_fetcher.py
97873ec verified
raw
history blame
824 Bytes
"""
Background price cache using public CoinGecko
(If you have Gemini keys, swap endpoints & add auth)
"""
import httpx, logging, os
COINGECKO_URL = (
"https://api.coingecko.com/api/v3/simple/price"
"?ids=bitcoin,ethereum,dogecoin&vs_currencies=usd"
)
CURRENT_PRICES = {"bitcoin": "‑‑", "ethereum": "‑‑", "dogecoin": "‑‑"}
def fetch_prices() -> None:
global CURRENT_PRICES
try:
resp = httpx.get(COINGECKO_URL, timeout=5)
resp.raise_for_status()
data = resp.json()
CURRENT_PRICES = {
"bitcoin": data["bitcoin"]["usd"],
"ethereum": data["ethereum"]["usd"],
"dogecoin": data["dogecoin"]["usd"],
}
logging.info("β›“ prices updated")
except Exception as e:
logging.warning(f"Price fetch failed: {e}")