×
Create a new article
Write your page title here:
We currently have 3,187 articles on s23. Type your article name above or create one of the articles listed here!



    s23
    3,187Articles

    Coingecko is a site to lookup prices of crypto currencies and stats. (https://www.coingecko.com)

    Here is some Python code to convert an ETH amount to the current USD value using their API.

    # convert an ETH amount to USD value, using Coingecko
    def eth2usd(amount):
        api_url="https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd"
        try:
            req = requests.get(api_url)
            req.raise_for_status()
        except Exception as err:
            print('failed to talk to Coingecko - {0} - {1}'.format(err.message, err.args))
            sys.exit(2)
        try:
            resp = req.json()
        except Exception as err:
            print('failed to parse JSON - {0} - {1}'.format(err.message, err.args))
            sys.exit(2)
        usd_value = float((resp['ethereum']['usd'] * amount))
        return usd_value
    
    total_usd=round(eth2usd(total_eth_eth))
    print('Total: ' + str(total_usd) + ' $ (@' + str(eth2usd(1)) + '$/Ξ)')
    
    
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.