Skip to content

Instantly share code, notes, and snippets.

@trestrantham
Last active November 10, 2018 15:03
Show Gist options
  • Save trestrantham/f71a575edf38fe11360f85007b37a419 to your computer and use it in GitHub Desktop.
Save trestrantham/f71a575edf38fe11360f85007b37a419 to your computer and use it in GitHub Desktop.
const https = require("https");
const KEY = "your-api-key";
const CURRENCY = "BTC";
const INTERVAL = "1h";
const PRICE = 6500;
let body = "";
let candles;
https.get(`https://api.nomics.com/v1/candles?key=${KEY}&interval=${INTERVAL}&currency=${CURRENCY}`, res => {
res.on("data", chunk => (body += chunk));
res.on("end", () => {
console.log(
JSON.parse(body).filter(candle => {
return (
(parseFloat(candle.open) <= PRICE && parseFloat(candle.close) >= PRICE) ||
(parseFloat(candle.close) <= PRICE && parseFloat(candle.open) >= PRICE)
);
})
);
});
});
@trestrantham
Copy link
Author

trestrantham commented Nov 10, 2018

$ node ./priceFinder.js
[ { timestamp: '2018-10-15T05:00:00Z',
    low: '5951.93031',
    open: '6320.69257',
    close: '6575.46387',
    high: '6745.00000',
    volume: '251651437' },
  { timestamp: '2018-10-21T19:00:00Z',
    low: '6377.99718',
    open: '6499.77948',
    close: '6500.61428',
    high: '6633.46405',
    volume: '26901571' },
  { timestamp: '2018-10-21T22:00:00Z',
    low: '6360.38577',
    open: '6508.58716',
    close: '6492.98875',
    high: '6627.69380',
    volume: '43365769' },
  { timestamp: '2018-10-22T07:00:00Z',
    low: '6368.13870',
    open: '6501.61815',
    close: '6489.73082',
    high: '6717.05361',
    volume: '47366101' },
  { timestamp: '2018-10-22T13:00:00Z',
    low: '6348.83206',
    open: '6500.16580',
    close: '6492.29237',
    high: '6629.38817',
    volume: '59026802' },
  { timestamp: '2018-10-24T04:00:00Z',
    low: '6325.14695',
    open: '6472.31950',
    close: '6515.92921',
    high: '6649.70534',
    volume: '48071972' },
  { timestamp: '2018-10-24T15:00:00Z',
    low: '6359.54352',
    open: '6507.20638',
    close: '6485.61203',
    high: '6773.28072',
    volume: '62903155' },
  { timestamp: '2018-10-25T01:00:00Z',
    low: '6348.05067',
    open: '6537.43458',
    close: '6483.00194',
    high: '6563.96955',
    volume: '56275491' },
  { timestamp: '2018-10-26T09:00:00Z',
    low: '6349.81716',
    open: '6523.50567',
    close: '6498.86933',
    high: '6585.78405',
    volume: '37749279' },
  { timestamp: '2018-11-07T00:00:00Z',
    low: '6441.56600',
    open: '6482.11471',
    close: '6530.40211',
    high: '6615.00000',
    volume: '130304063' },
  { timestamp: '2018-11-08T15:00:00Z',
    low: '6450.68082',
    open: '6510.41944',
    close: '6489.76871',
    high: '6570.71132',
    volume: '40037208' } ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment