ohlc-aggregator
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:
time: 8:59am
time: 9:00am
time: 9:01am
time: 9:02am
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:
time: 8:59am
time: 9:00am
time: 9:01am
time: 9:02am
time: 9:03am
time: 9:04am
time: 9:05am
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 candleslet ohlc_aggregate = ;var moment = ; // Converting 1m candles to 5min candles:let result = ; console;
See test/test.js for more examples.