Files
BTC-Portfolio/btc-portfolio/backend/app/services/btc.py
T
Jonathan 541b5f57d2 Add 1-year BTC daily price history chart
New GET /history endpoint fetches 365 days of BTC/EUR data from
CoinGecko, deduplicates by date, and joins the user's purchases.
BTCHistoryChart component renders the price line with orange dot
markers on purchase dates and a dashed cyan avg buy price line.
Tooltip shows purchase details on marked dates.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 23:18:40 +01:00

28 lines
785 B
Python

import requests
def get_btc_history_eur() -> list:
try:
resp = requests.get(
"https://api.coingecko.com/api/v3/coins/bitcoin/market_chart",
params={"vs_currency": "eur", "days": "365", "interval": "daily"},
timeout=15,
)
resp.raise_for_status()
return resp.json().get("prices", []) # [[timestamp_ms, price], ...]
except Exception:
return []
def get_btc_price_eur() -> float:
try:
resp = requests.get(
"https://api.coingecko.com/api/v3/simple/price",
params={"ids": "bitcoin", "vs_currencies": "eur"},
timeout=10,
)
resp.raise_for_status()
return float(resp.json()["bitcoin"]["eur"])
except Exception:
return 0.0