This is a playground to test JavaScript. It runs a completely standard copy of Node.js on a virtual server created just for you. Every one of npm’s 300,000+ packages are pre-installed, so try it out:
var nsynjs = require('nsynjs');
var popsicle = require('popsicle');
var getEthPriceHistorical = function(popsicle, toSymbol) {
var histData = {};
var ts;
for (var i = 1; i < 5; i++){
ts = new Date(new Date().getTime() - (24*i * 60 * 60 * 1000));
if (typeof toSymbol === 'string') {
toSymbol = toSymbol.toUpperCase();
} else {
toSymbol = 'USD,EUR,GBP,CHF,THB,AUD,INR';
}
var data = popsicle.request({
method: 'POST',
url: 'https://min-api.cryptocompare.com/data/pricehistorical',
query: {
fsym: 'ETH',
tsyms: toSymbol,
timestamp: ts
}
})
.data.body;
histData[ts] = JSON.parse(data);
console.log(ts+", got: "+data);
}
return histData;
}
var ctx = nsynjs.run(getEthPriceHistorical,{},popsicle,null,function(histData){
console.log('done: '+ JSON.stringify(histData));
});
1;