New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ohlc-aggregator

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ohlc-aggregator

Aggregates ohlcv values into coarse grain intervals

  • 1.0.16
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
decreased by-65.38%
Maintainers
1
Weekly downloads
 
Created
Source

ohlc-aggregator

NPM NPM Downloads

Aggregates ohlcv candle values into predictable coarse-grained intervals. The intervals should be either minutes, hours, or days.

The difference between this package and other packages is that rather than simply aggregating each n candles into a group, we create predictable interval where the start time of each interval is divisible by n. If some candles from an interval are missing, we still create those interval.

Example 1

In converting 1m to 5m candles, a naive implementation creates only one group for the following 5 candles:

  1. time: 8:59am
  2. time: 9:00am
  3. time: 9:01am
  4. time: 9:02am
  5. time: 9:03am

However, this package creates two groups based on predictable timing intervals, i.e., the start of each timing interval is divisible by 5m:

  • Group 1: 8:55 to 8:59
  • Group 2: 9:00 to 9:05

We create two groups although some candles are missing from each group.

Example 2

Consider these candles:

  1. time: 8:59am
  2. time: 9:00am
  3. time: 9:01am
  4. time: 9:02am
  5. time: 9:03am
  6. time: 9:04am
  7. time: 9:05am
  8. time: 9:06am

A naive implementation will create these groups:

  • Group 1: 8:59 to 9:03, (complete candle)
  • Group 2: 9:04 to 9:06, (incomplete candle)

However, a predictable grouping would be:

  • Group 1: 8:55 to 9:00, (incomplete candle)
  • Group 1: 9:00 to 9:04, (complete candle)
  • Group 2: 9:05 to 9:09, (incomplete candle)

Again, the start of each timing interval is divisible by 5m.

Install

npm i -s ohlc-aggregator

Usage

// Converting 1m to 5m candles
let ohlc_aggregate = require("ohlc-aggregator");
var moment = require("moment");

// Converting 1m candles to 5min candles:
let result = ohlc_aggregate(
  [
    {
      time: moment("10/15/2017 8:59", "M/D/YYYY H:mm").valueOf(), // timestamp in milliseconds
      open: 1,
      high: 5,
      low: 1,
      close: 2,
      volume: 100
    },
    {
      time: moment("10/15/2017 9:00", "M/D/YYYY H:mm").valueOf(), // timestamp in milliseconds
      open: 1,
      high: 5,
      low: 1,
      close: 2,
      volume: 100
    },
    {
      time: moment("10/15/2017 9:01", "M/D/YYYY H:mm").valueOf(), // timestamp in milliseconds
      open: 3,
      high: 10,
      low: 0,
      close: 6,
      volume: 200
    }
  ],
  /*intervalRatio=*/ 5,   // ration between original interval and the desired interval
  /*intervalInSeconds=*/, 5 * 60 // Interval duration in seconds
  /*arrayTimeCoefficient=*/ 1 // Set this to 1000 if the time values are in second
);

console.log("result: ", JSON.stringify(result, null, 1));

See test/test.js for more examples.

Keywords

FAQs

Package last updated on 04 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc