npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

candles-convert

v0.0.12

Published

yet another util to convert the time-duration of OHLCV candles. results are either naively merged with n-candle chunks or can be time-aligned to the clock so that, ex: 15min candles start at 10:00, 10:15 etc

Downloads

10

Readme

candles-convert

Yet another util to convert the time-duration of OHLCV candles. results are either naively merged with n-candle chunks or can be time-aligned to the clock so that, ex: 15min candles start at 10:00, 10:15 etc

Experimental, use at your own risk.

Installation

npm i candles-convert

Usage

var {
    convertToNMinuteIntervalsFromDate,
    convertToNMinuteIntervalsFromTime,
    convertToNPeriodIntervals} = require('candles-convert');

var timeRoundingFunction = Math.round; //round to nearest time boundary. 11:59 merges into candle for 12:00. makes for a cleaner example here but is less realistic.
// var timeRoundingFunction = Math.floor; //default -- round down. 11:59 merges into candle for 11:00 [assuming 1hr interval]

//candles with time in unix epoch seconds, and an arbitrary extra field "some_extraParam"
const candlesWithTime = [
  { time: 1685267880, open: 10, high: 12, low: 9,  close: 11, volume: 100, some_extraParam: 1},
  { time: 1685268060, open: 11, high: 13, low: 10, close: 12, volume: 150, some_extraParam: 2},
  { time: 1685268180, open: 12, high: 14, low: 11, close: 13, volume: 120, some_extraParam: 3},
  { time: 1685268480, open: 13, high: 15, low: 12, close: 14, volume: 180, some_extraParam: 4},
  { time: 1685268840, open: 14, high: 16, low: 13, close: 15, volume: 200, some_extraParam: 5},
  { time: 1685269020, open: 15, high: 17, low: 14, close: 16, volume: 140, some_extraParam: 6}
];

const convertedCandles = convertToNMinuteIntervalsFromTime(candlesWithTime, 15, timeRoundingFunction);
console.log(convertedCandles);

//notice how any 'extra params' are absorbed into the result form the first candle in each merged set
// [
//   { "time": 1685268000, "open": 10, "high": 14, "low": 9, "close": 13, "volume": 370, "nSrcCandles": 3, "some_extraParam": 1 },
//   { "time": 1685268900, "open": 13, "high": 17, "low": 12, "close": 16, "volume": 520, "nSrcCandles": 3, "some_extraParam": 4 }
// ]

//candles with date as iso string
const candlesWithDateStrings = [
  { date: "2023-05-28T09:58:00.000Z", open: 10, high: 12, low: 9, close: 11, volume: 100 },
  { date: "2023-05-28T10:01:00.000Z", open: 11, high: 13, low: 10, close: 12, volume: 150 },
  { date: "2023-05-28T10:03:00.000Z", open: 12, high: 14, low: 11, close: 13, volume: 120 },
  { date: "2023-05-28T10:08:00.000Z", open: 13, high: 15, low: 12, close: 14, volume: 180 },
  { date: "2023-05-28T10:14:00.000Z", open: 14, high: 16, low: 13, close: 15, volume: 200 },
  { date: "2023-05-28T10:17:00.000Z", open: 15, high: 17, low: 14, close: 16, volume: 140 }
];

const convertedCandles2 = convertToNMinuteIntervalsFromDate(candlesWithDateStrings, 15, timeRoundingFunction);
console.log(convertedCandles2);

// [
//   { "date": "2023-05-28T10:00:00.000Z", "open": 10, "high": 14, "low": 9, "close": 13, "volume": 370, "nSrcCandles": 3 },
//   { "date": "2023-05-28T10:15:00.000Z", "open": 13, "high": 17, "low": 12, "close": 16, "volume": 520, "nSrcCandles": 3 }
// ]

//naively merge candles as chunks of length n
const convertedCandles3 = convertToNPeriodIntervals(candlesWithDateStrings, 3);
console.log(convertedCandles3);

// [
//   { "date": "2023-05-28T09:58:00.000Z", "open": 10, "high": 14, "low": 9, "close": 13, "volume": 370, "nSrcCandles": 3 },
//   { "date": "2023-05-28T10:08:00.000Z", "open": 13, "high": 17, "low": 12, "close": 16, "volume": 520, "nSrcCandles": 3 }
// ]

stonks