Skip to content

Instantly share code, notes, and snippets.

@gka gka/_cryptocrash-scaper.md
Last active Feb 28, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.