from binance.client import Client
import datetime

c = Client()
klines = c.get_klines(symbol='ETHUSDT', interval='15m', limit=50)

print('\n📊 ETH - Analyse Historique (Chandelles 15min):')
print('='*70)

for k in klines[-30:]:
    ts = datetime.datetime.fromtimestamp(k[0]/1000).strftime('%H:%M')
    o = float(k[1])
    h = float(k[2])
    l = float(k[3])
    cl = float(k[4])
    var = ((cl-o)/o*100)
    
    # Détection de 9h20
    hour_min = datetime.datetime.fromtimestamp(k[0]/1000).strftime('%H:%M')
    marker = "  ⭐ 9h20" if hour_min in ['09:15', '09:20', '09:30'] else ""
    
    print(f'{ts} | Open:{o:.2f}€ High:{h:.2f}€ Low:{l:.2f}€ Close:{cl:.2f}€ | Δ:{var:+.2f}%{marker}')

# Calculer RSI approximatif sur les dernières bougies
print('\n' + '='*70)
print('📈 Analyse technique autour de 9h20:')

# Trouver la bougie de 9h15-9h30
target_klines = []
for k in klines:
    ts_str = datetime.datetime.fromtimestamp(k[0]/1000).strftime('%H:%M')
    if ts_str in ['09:00', '09:15', '09:30']:
        target_klines.append({
            'time': ts_str,
            'open': float(k[1]),
            'high': float(k[2]),
            'low': float(k[3]),
            'close': float(k[4])
        })

if target_klines:
    print('\nBougies clés autour de 9h20:')
    for kl in target_klines:
        print(f"  {kl['time']}: {kl['close']:.2f}€")
else:
    print('  ⚠️ Pas de données pour 9h20 (trop anciennes)')
