from binance.client import Client

# Binance API credentials (public data does not require authentication)
api_key = 'WFIEaBuUafZ9ldAiMHLZ4Z1qHdVnpoDUVZM8MughMf6zmbSqGx5pEmQFBJysjwFp'  # Optional for public data
api_secret = 'C9HtmLk7fBCidyJI2lPtUbYhj4T0FdmJ0NE0LLipFiwUSR7euf1TEzJblEx1O6oA'  # Optional for public data

# Initialize Binance client
client = Client(api_key, api_secret)

# List of top 5 popular cryptocurrencies (symbols)
top_cryptos = ['BTCUSDT', 'ETHUSDT', 'BNBUSDT', 'SOLUSDT', 'XRPUSDT']

# Function to fetch and display crypto info
def get_crypto_info(symbol):
    try:
        ticker = client.get_symbol_ticker(symbol=symbol)
        stats = client.get_ticker(symbol=symbol)
        
        price = ticker['price']
        price_change_percent = stats['priceChangePercent']
        
        print(f"Symbol: {symbol}")
        print(f"Price: {price} USDT")
        print(f"24h Change: {price_change_percent}%")
        print("-" * 30)
    
    except Exception as e:
        print(f"Error fetching data for {symbol}: {e}")

# Main function to fetch info for top 5 cryptos
def fetch_top_crypto_prices():
    for crypto in top_cryptos:
        get_crypto_info(crypto)

if __name__ == "__main__":
    fetch_top_crypto_prices()
