Spaces:
Running
Running
File size: 824 Bytes
97873ec |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
"""
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}")
|