#!/usr/bin/env python3
"""Script pour vérifier le solde testnet"""
from config import BINANCE_API_KEY, BINANCE_API_SECRET
import hmac, hashlib, time, requests

base_url = 'https://testnet.binance.vision'
timestamp = int(time.time() * 1000)
params = f'timestamp={timestamp}'
signature = hmac.new(BINANCE_API_SECRET.encode(), params.encode(), hashlib.sha256).hexdigest()

headers = {'X-MBX-APIKEY': BINANCE_API_KEY}
r = requests.get(f'{base_url}/api/v3/account?{params}&signature={signature}', headers=headers)
data = r.json()

if 'balances' in data:
    print('=== SOLDE TESTNET BINANCE ===')
    total_usdt = 0
    for b in data['balances']:
        free = float(b['free'])
        locked = float(b['locked'])
        if free > 0 or locked > 0:
            print(f"  {b['asset']}: {free:.4f} (libre) + {locked:.4f} (bloqué)")
            if b['asset'] == 'USDT':
                total_usdt = free + locked
    print(f"\n💰 Total USDT: {total_usdt:.2f}")
else:
    print('Erreur:', data)
