Skip to content

Instantly share code, notes, and snippets.

@vikiival
Created December 3, 2020 17:32
Show Gist options
  • Save vikiival/22248d32233b57af0333cf8d7cb56018 to your computer and use it in GitHub Desktop.
Save vikiival/22248d32233b57af0333cf8d7cb56018 to your computer and use it in GitHub Desktop.
Price of Kusama (KSM) for last 30 days
from pycoingecko import CoinGeckoAPI
import datetime
from statistics import median, mean
cg = CoinGeckoAPI()
def main():
numdays = 30
base = datetime.datetime.today()
date_list = [base - datetime.timedelta(days=x) for x in range(numdays)]
fn_format = lambda x: x.strftime("%d-%m-%Y")
fn_gecko = lambda date: cg.get_coin_history_by_id(id='kusama', vs_currencies='eur', date=date)
fn_price = lambda x: x['market_data']['current_price']['eur']
prices = sorted(map(fn_price, map(fn_gecko, map(fn_format, date_list))))
print('MEDIAN', median(prices))
print('MEAN', mean(prices))
return prices
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment