I have the code below which currently pulls pricing data for Ethereum from CoinGecko API. From this request I am building a dictionary that contains the pieces of information and returning it to be used elsewhere in my code.
This function works fine, but I can't help think it could be written so much shorter than this.
How could this be written differently and shorter?
def get_ethereum_data():
ethereum_data = {}
response = requests.get(f"{COINGECKO_COIN_URL}")
response.raise_for_status()
data = response.json()
ethereum_data["current_price"] = data["market_data"]["current_price"]["usd"]
ethereum_data["market_cap"] = data["market_data"]["market_cap"]["usd"]
ethereum_data["ath"] = data["market_data"]["ath"]["usd"]
ethereum_data["ath_percentage"] = data["market_data"]["ath_change_percentage"]["usd"]
ethereum_data["24h_percentage"] = data["market_data"]["price_change_percentage_24h"]
ethereum_data["7d_percentage"] = data["market_data"]["price_change_percentage_7d"]
ethereum_data["30d_percentage"] = data["market_data"]["price_change_percentage_30d"]
ethereum_data["1y_percentage"] = data["market_data"]["price_change_percentage_1y"]
return ethereum_data