CoingGecko coins:
https://api.coingecko.com/api/v3/coins/list
import requests
import time
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()}.")
time.sleep(3)
Python