Versiones iniciales

This commit is contained in:
2025-06-16 10:39:30 +00:00
commit e56761aac5
4 changed files with 178 additions and 0 deletions

View File

@ -0,0 +1,69 @@
#!/bin/bash
# === CONFIGURACIÓN ===
COIN_ID="tether"
VS_CURRENCY="eur"
OUTPUT="usdt-eur-2025-average-gmt1.csv"
INICIO=2024-12-01
FIN=2026-12-01
# === Timestamps UNIX UTC ===
if date -j -f "%Y-%m-%d" "2025-01-01" +"%s" >/dev/null 2>&1; then
# -- Version MacOS --
FROM_TIMESTAMP=$(date -j -f "%Y-%m-%d" "$INICIO" +"%s")
TO_TIMESTAMP=$(date -j -f "%Y-%m-%d" "$FIN" +"%s")
else
# -- Versión Linux --
FROM_TIMESTAMP=$(date -d "$INICIO" +"%s")
TO_TIMESTAMP=$(date -d "$FIN" +"%s")
fi
# === Llamada API ===
URL="https://api.coingecko.com/api/v3/coins/${COIN_ID}/market_chart/range?vs_currency=${VS_CURRENCY}&from=${FROM_TIMESTAMP}&to=${TO_TIMESTAMP}"
echo "📡 Llamando a: $URL"
RESPONSE=$(curl -s "$URL")
# Verifica si viene campo .prices
if ! echo "$RESPONSE" | jq '.prices' | grep -q '\['; then
echo "❌ No se encontraron precios en la respuesta de CoinGecko."
exit 1
fi
# === Cabecera CSV ===
echo "fecha_gmt1,avg_usdt_eur" > "$OUTPUT"
# === Procesamiento + agrupación por fecha española ===
export LC_NUMERIC=C
echo "$RESPONSE" | jq -c '.prices[]' \
| while read -r entry; do
ts_ms=$(echo "$entry" | jq '.[0]')
price=$(echo "$entry" | jq '.[1]')
# Verifica que price sea válido
if [[ "$price" == "null" || -z "$price" ]]; then continue; fi
# Convertir a hora española (Europe/Madrid)
ts_s=$((ts_ms/1000))
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
date_es=$(TZ=Europe/Madrid date -j -f "%s" "$ts_s" "+%Y-%m-%d")
else
# Linux
date_es=$(TZ=Europe/Madrid date -d "@$ts_s" "+%Y-%m-%d")
fi
echo "$date_es,$price"
done \
| awk -F, '
{
sum[$1] += $2;
count[$1]++;
}
END {
for (d in sum)
printf "%s,%.6f\n", d, sum[d]/count[d];
}' | sort >> "$OUTPUT"
echo "✅ Exportado como $OUTPUT (en horario de España)"

45
get-usdt-eur-range.py Normal file
View File

@ -0,0 +1,45 @@
#!/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)")

34
get-usdt-eur-range.sh Normal file
View File

@ -0,0 +1,34 @@
#!/bin/bash
# === CONFIGURACIÓN ===
COIN_ID="tether"
VS_CURRENCY="eur"
OUTPUT="usdt-eur-2025.csv"
# Timestamps UNIX para 2025-01-01 → 2026-01-01
FROM_TIMESTAMP=$(date -j -f "%Y-%m-%d" "2025-01-01" +"%s")
TO_TIMESTAMP=$(date -j -f "%Y-%m-%d" "2026-01-01" +"%s")
# === Llamada API ===
URL="https://api.coingecko.com/api/v3/coins/$COIN_ID/market_chart/range?vs_currency=$VS_CURRENCY&from=$FROM_TIMESTAMP&to=$TO_TIMESTAMP"
echo "📡 Llamando a CoinGecko..."
RESPONSE=$(curl -s "$URL")
# === CSV: cabecera ===
echo "date_utc,date_gmt1,usdt_eur" > "$OUTPUT"
# === Procesar respuesta JSON ===
echo "$RESPONSE" | jq -c '.prices[]' | while read -r entry; do
ts_ms=$(echo "$entry" | jq '.[0]')
price=$(echo "$entry" | jq '.[1]')
# UTC (timestamp → fecha UTC)
date_utc=$(date -u -r "$((ts_ms/1000))" "+%Y-%m-%d %H:%M:%S")
# GMT+1
date_gmt1=$(TZ=Europe/Madrid date -r "$((ts_ms/1000))" "+%Y-%m-%d %H:%M:%S")
echo "$date_utc,$date_gmt1,$price"
done | sort | uniq -f0 >> "$OUTPUT"
echo "✅ Exportado como $OUTPUT"

30
get-usdt-eur.sh Normal file
View File

@ -0,0 +1,30 @@
#!/bin/bash
OUTPUT="usdt-eur-2025.csv"
> "$OUTPUT"
echo '"date","usdt_eur"' > "$OUTPUT"
START_DATE="2025-01-01"
END_DATE="2025-01-31"
CURRENT_DATE="$START_DATE"
while [[ "$CURRENT_DATE" < "$END_DATE" ]]; do
# Formatear fecha como DD-MM-YYYY (requerido por CoinGecko)
FORMATTED=$(date -j -f "%Y-%m-%d" "$CURRENT_DATE" "+%d-%m-%Y")
echo "🔄 Consultando precio para $CURRENT_DATE..."
PRICE=$(curl -s "https://api.coingecko.com/api/v3/coins/tether/history?date=${FORMATTED}&localization=false" \
| jq -r '.market_data.current_price.eur // empty')
if [[ -n "$PRICE" ]]; then
echo "\"$CURRENT_DATE\",\"$PRICE\"" >> "$OUTPUT"
else
echo "\"$CURRENT_DATE\",\"N/A\"" >> "$OUTPUT"
fi
CURRENT_DATE=$(date -j -v+1d -f "%Y-%m-%d" "$CURRENT_DATE" "+%Y-%m-%d")
sleep 2 # Evita ser bloqueado por CoinGecko
done
echo "✅ Exportado como $OUTPUT"