Calculating & Displaying crypto currency with CoinGecko

CoingGecko coins: https://api.coingecko.com/api/v3/coins/list, look for the ids in this url and use them in quantities dict, here are some popular currencies:

  • bitcoin
  • ethereum
  • ripple
  • binancecoin
  • dogecoin

 

Change the currency variable if necessary, some popular options are:

  • usd: US Dollar
  • eur: Euro
  • gbp: British Pound
  • jpy: Japanese Yen
  • aud: Australian Dollar
     
  • btc: Bitcoin
  • eth: Ethereum
  • usdt: Tether
  • bnb: Binance Coin
  • xrp: XRP

 

pip install requests

 

import requests

def get_crypto_prices(cryptos, currency='eur'):
    crypto_ids = ','.join(cryptos)
    url = f'https://api.coingecko.com/api/v3/simple/price?ids={crypto_ids}&vs_currencies={currency}'
    
    try:
        response = requests.get(url)
        response.raise_for_status() 
        data = response.json()
        return {crypto: data[crypto][currency] for crypto in cryptos}
    
    except requests.RequestException as e:
        print(f"Error: {e}")
        return None



currency = 'eur'

quantities = {
    'bitcoin': 0.00114522,
    'ripple': 319.33343233,  
    'stellar': 449.44127517  
}

cryptos = list(quantities.keys())
prices = get_crypto_prices(cryptos, currency)

if prices:
    total_value = 0
    for crypto, amount in quantities.items():
        price = prices[crypto]
        value = amount * price
        total_value += value
        print(f"{amount} {crypto.capitalize()} worth {value:.2f} {currency.upper()}.")
    
    print(f"Total: {total_value:.2f} {currency.upper()}.")

Python


06 Jan. 2025 | Last Updated: 22 Nov. 2025 | jaimedcsilva

Related
  • Printing CMD with colors
  • Calculating & Displaying crypto currency with CoinGecko
  • Creatin an .exe file to run a Python script
  • Getting certificate chains from websites
  • Getting the complete trustchain of a website
  • Installing pip in embedded Python - Full Guide
  • Cython - Hiding Python Code
  • How to Send Emails with Python’s smtplib
  • Generating QR Codes with Python

  • Buy Me a Coffee