Commit 259fd5b5 authored by Stephane Mankowski's avatar Stephane Mankowski

cryptocompare source support now intervals

parent da841140
......@@ -29,8 +29,10 @@ import json
import sys
units=sys.argv[1].split('-')
# url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/historical?symbol='+units[0]+'&convert='+units[1]+'&time_start='+sys.argv[2]+'T00:00:00.000Z&time_end='+sys.argv[3]+'T23:59:59.000Z'
url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol='+units[0]+'&convert='+units[1]
req = Request('https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol='+units[0]+'&convert='+units[1])
req = Request(url)
req.add_header("X-CMC_PRO_API_KEY", sys.argv[5])
f = urlopen(req)
print("Date,Price")
......
......@@ -27,11 +27,16 @@
import urllib.request
import json
import sys
import time
import datetime
units=sys.argv[1].split('-')
mode = sys.argv[4]
f = urllib.request.urlopen('https://min-api.cryptocompare.com/data/v2/histoday?fsym='+units[0]+'&tsym='+units[1]+'&limit=1000&api_key='+sys.argv[5])
nb = (datetime.datetime.strptime(sys.argv[2], '%Y-%m-%d')-datetime.datetime.strptime(sys.argv[3], '%Y-%m-%d')).days
url = 'https://min-api.cryptocompare.com/data/v2/histoday?fsym='+units[0]+'&tsym='+units[1]+'&limit='+str(nb)+'&api_key='+sys.argv[5]
f = urllib.request.urlopen(url)
print("Date,Price")
for item in json.loads(f.read().decode('utf-8'))['Data']['Data']:
print(time.strftime('%Y-%m-%d', time.gmtime(int(item["time"])))+','+str(item['close']))
d = datetime.datetime.fromtimestamp(int(item["time"]))
if mode == '1d' or (mode=='1w' and d.isoweekday()==1) or (mode=='1mo' and d.day==1):
print(d.strftime('%Y-%m-%d')+','+str(item['close']))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment