Created
March 14, 2021 08:07
-
-
Save MosheStauber/3b4d95fd523b5833250a853c221efb32 to your computer and use it in GitHub Desktop.
Script to get total ethereum market cap - including the marketcap of all tokens on Ethereum!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Script to get total ethereum market cap - including the marketcap of all tokens on Ethereum! | |
Script expects existence of API_KEY in environment vars for coinmarketcap api | |
--- | |
Output from last run on 2021-03-14: | |
Retrieved 4328 cryptocurrencies | |
Retrieved 2693 Ethereum tokens | |
Total token market cap: $192,452,534,460.19403 | |
Total Ethereum market cap: $217,180,649,459.69635 | |
Total total Ethereum market cap: $409,633,183,919.8904 | |
""" | |
import requests | |
import os | |
API_KEY = os.environ['API_KEY'] | |
HEADERS = { | |
'Accepts': 'application/json', | |
'X-CMC_PRO_API_KEY': API_KEY, | |
} | |
def get_cryptos(): | |
crypto_list_url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest' | |
parameters = { | |
'start':'1', | |
'limit':'5000', | |
} | |
response = requests.get(crypto_list_url, params=parameters, headers=HEADERS) | |
if not response.ok: | |
print("Nahyo, response no bueno. Exiting") | |
exit(1) | |
data = response.json()['data'] | |
print(f'Retrieved {len(data)} cryptocurrencies') | |
return data | |
if __name__ == '__main__': | |
data = get_cryptos() | |
tokens = [d for d in data if d['platform'] and d['platform']['symbol'] == 'ETH'] | |
print(f'Retrieved {len(tokens)} Ethereum tokens') | |
token_market_cap = sum([d['quote']['USD']['market_cap'] for d in tokens]) | |
print(f'Total token market cap: ${token_market_cap:,}') | |
eth = [d for d in data if d['symbol'] == 'ETH'][0] | |
eth_market_cap = eth['quote']['USD']['market_cap'] | |
print(f"Total Ethereum market cap: ${eth_market_cap:,}") | |
print(f"Total total Ethereum market cap: ${eth_market_cap + token_market_cap:,}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment