Spaces:
Sleeping
Sleeping
""" | |
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}") | |