46 lines
1.3 KiB
Python
Executable File
46 lines
1.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import requests
|
|
import pandas as pd
|
|
from datetime import datetime
|
|
import time
|
|
|
|
# === Configuración ===
|
|
coin = "tether"
|
|
vs_currency = "eur"
|
|
start_date = datetime(2025, 1, 1)
|
|
end_date = datetime(2026, 1, 1)
|
|
|
|
# === Convertir a timestamps UNIX en segundos ===
|
|
from_ts = int(start_date.timestamp())
|
|
to_ts = int(end_date.timestamp())
|
|
|
|
# === URL de CoinGecko ===
|
|
url = f"https://api.coingecko.com/api/v3/coins/{coin}/market_chart/range"
|
|
params = {
|
|
"vs_currency": vs_currency,
|
|
"from": from_ts,
|
|
"to": to_ts
|
|
}
|
|
|
|
print("📡 Solicitando datos a CoinGecko...")
|
|
response = requests.get(url, params=params)
|
|
if response.status_code != 200:
|
|
print("❌ Error en la solicitud:", response.status_code)
|
|
exit(1)
|
|
|
|
data = response.json()
|
|
prices = data.get("prices", [])
|
|
|
|
# === Convertir a DataFrame ===
|
|
df = pd.DataFrame(prices, columns=["timestamp_ms", "usdt_eur"])
|
|
df["timestamp"] = pd.to_datetime(df["timestamp_ms"], unit="ms")
|
|
df["date"] = df["timestamp"].dt.date
|
|
|
|
# === Agrupar por fecha y tomar el primer valor de cada día ===
|
|
df_daily = df.groupby("date").first().reset_index()[["date", "usdt_eur"]]
|
|
|
|
# === Guardar CSV ===
|
|
output_file = "usdt-eur-2025.csv"
|
|
df_daily.to_csv(output_file, index=False)
|
|
print(f"✅ Exportado como {output_file} ({len(df_daily)} días)")
|