Skip to content

Instantly share code, notes, and snippets.

@cdm
Created October 20, 2021 08:09
Show Gist options
  • Save cdm/e1cb562d3ad3beb5f83ce90de81363f9 to your computer and use it in GitHub Desktop.
Save cdm/e1cb562d3ad3beb5f83ce90de81363f9 to your computer and use it in GitHub Desktop.
import requests
import pandas
print("Loading $VEGA historic daily price data from CoinGecko API")
url = "https://api.coingecko.com/api/v3/coins/vega-protocol/market_chart?vs_currency=usd&days=max&interval=daily"
response = requests.get(url)
response_json = response.json()
dict = {
"dates": [],
"prices": []
}
for price_item in response_json["prices"]:
unix_conversion=pandas.to_datetime(price_item[0], unit='ms')
dict["dates"].append(unix_conversion)
dict["prices"].append(price_item[1])
df = pandas.DataFrame(dict)
calcs = df.groupby(df['dates'].dt.strftime('%B %Y'))['prices'].mean()
print("---")
print(df)
print("---")
print("Average (mean) prices for daily data available:")
print("*** NOTE: Will calculate partial months, if data is missing or we're part month ***")
print("---")
print(calcs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment