mgbam commited on
Commit
97873ec
Β·
verified Β·
1 Parent(s): 448d7a9

Create app/price_fetcher.py

Browse files
Files changed (1) hide show
  1. app/price_fetcher.py +27 -0
app/price_fetcher.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Background price cache using public CoinGecko
3
+ (If you have Gemini keys, swap endpoints & add auth)
4
+ """
5
+ import httpx, logging, os
6
+
7
+ COINGECKO_URL = (
8
+ "https://api.coingecko.com/api/v3/simple/price"
9
+ "?ids=bitcoin,ethereum,dogecoin&vs_currencies=usd"
10
+ )
11
+
12
+ CURRENT_PRICES = {"bitcoin": "‑‑", "ethereum": "‑‑", "dogecoin": "‑‑"}
13
+
14
+ def fetch_prices() -> None:
15
+ global CURRENT_PRICES
16
+ try:
17
+ resp = httpx.get(COINGECKO_URL, timeout=5)
18
+ resp.raise_for_status()
19
+ data = resp.json()
20
+ CURRENT_PRICES = {
21
+ "bitcoin": data["bitcoin"]["usd"],
22
+ "ethereum": data["ethereum"]["usd"],
23
+ "dogecoin": data["dogecoin"]["usd"],
24
+ }
25
+ logging.info("β›“ prices updated")
26
+ except Exception as e:
27
+ logging.warning(f"Price fetch failed: {e}")