this is the script I used to download and transform the data for this chart https://www.datawrapper.de/_/l4GNH/
Last active
February 28, 2019 11:43
Star
You must be signed in to star a gist
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
const fs = require('fs'); | |
const request = require('request'); | |
const moment = require('moment'); | |
const d3 = require('d3-dsv'); | |
var data = []; | |
const dataByTs = {}; | |
let currencies = ['ETH','XRP','LTC','XEM','XMR','ADA','DASH','BCH','BTC']; | |
const output = 'USD'; | |
function get(curr, ts) { | |
const url = `https://min-api.cryptocompare.com/data/histominute?fsym=${curr}&tsym=${output}&limit=1440&aggregate=3&e=CCCAGG` + (ts ? '&toTs='+ts : ''); | |
console.log(url, ts); | |
request(url, (err, res, body) => { | |
body = JSON.parse(body); | |
body.Data.forEach(r => { | |
if (!dataByTs[r.time]) { | |
dataByTs[r.time] = { time: moment(r.time*1000).format("YYYY-MM-DD HH:mm:ss") }; | |
data.push(dataByTs[r.time]); | |
} | |
const row = dataByTs[r.time]; | |
row[curr] = r.close; | |
// console.log(row); | |
}); | |
if (now - body.TimeFrom < 24 * 60 * 60) get(curr, body.TimeFrom-60); | |
else if (currencies.length) get(currencies.shift(), now); | |
else { | |
data = data.sort((a,b) => { | |
return a.time > b.time ? 1 : -1; | |
}); | |
console.log(data[0]); | |
const newdata = []; | |
data.forEach(row => { | |
console.log(row.time); | |
const nr = {time:row.time}; | |
Object.keys(row).forEach(k => { | |
if (k != 'time') { | |
nr[k] = row[k] / data[0][k]*100; | |
} | |
// normalise | |
}); | |
// console.log(r); | |
newdata.push(nr); | |
}); | |
fs.writeFileSync('data-hist.csv', d3.csvFormat(newdata)); | |
} | |
}); | |
} | |
get(currencies.shift(), now); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment