coinigy-private-api

node v6.14.1
version: 0.0.4
endpointsharetweet
// REST setup functions var express = require("@runkit/runkit/express-endpoint/1.0.0"); var app = express(exports); var bodyParser = require('body-parser'); app.use(bodyParser.urlencoded({ extended: false })); // 3rd party dependencies and configs let moment = require('moment'); let got = require('got');
let getTicks = module.exports.getTicks = async function (asset, currency, exchange, period = 60, start=moment().subtract(period * 24, 'minutes').unix(), end = moment().unix()) { start = start || moment().subtract(period * 15, 'minutes').unix(); let url = `https://www.coinigy.com/getjson/chart_feed/${exchange}/${currency}/${asset}/${period < 1440 ? period : 'D'}/${start}/${end}`; let data = await got(url).then((d) => JSON.parse(d.body)); return data.map((d) => { return { start: moment.unix(d[0]).format(), open: parseFloat(d[1]), high: parseFloat(d[2]), low: parseFloat(d[3]), close: parseFloat(d[4]), vol: parseFloat(d[5]), end: moment.unix(d[6]).format() } }); }
// REST route configuration app.get('/:currency/:asset?/:exchange?', async function (req, res) { console.log(req.params.asset, req.params.currency, req.params.exchange); try { let ticks = await getTicks(req.params.asset, req.params.currency, req.params.exchange); return res.send(ticks); } catch (err) { res.status(500).send(err); } });
// test await getTicks('ETH', 'BTC', 'PLNX', 1440);
Loading…

no comments

    sign in to comment