High-precision OHLC transformation with strict anchor time alignment.
- Strict Anchor Alignment: Ensures candles align with specific sessions (e.g., 4h candle starting at 23:00).
- High Performance: Batch processing optimized for thousands of candles.
- Flexible Timeframes: Supports
m,h,dinputs.
deno add jsr:@neabyte/candle-transformimport { Transform } from '@neabyte/candle-transform'
// 1m data input
const data = [
{ time: 1704067200000, open: 1.0, high: 2.0, low: 0.9, close: 1.5 },
{ time: 1704067260000, open: 1.5, high: 2.5, low: 1.4, close: 2.0 },
{ time: 1704067320000, open: 2.0, high: 3.0, low: 1.8, close: 2.5 }
// ... more candles
]
// Convert to 4-hour chart (Default Anchor 23:00 UTC)
const h4 = Transform.from(data).to('4h')
console.log(h4) // Output: [ { time: 1704063600000, open: 1, high: 2, low: 0.5, close: 1.5, ... }, ... ]
// Convert to 1-day chart with custom anchor (e.g., 00:00 UTC)
const daily = Transform.from(data).anchor(0).to('1d')
console.log(daily) // Output: [ { time: 1704063600000, open: 1, high: 2, low: 0.5, close: 1.5, ... }, ... ]Creates a transformation instance from source data.
Parameters:
data: CandleData[]- Array of source candles
Sets the anchor hour in UTC for time alignment.
Parameters:
hour: number- Hour (0-23). Default is23(23:00 UTC Market Open)
Executes the transformation.
Parameters:
timeframe: TimeframeStr- Target timeframe (e.g.,'15m','4h','1d')
Returns: CandleData[] - Transformed candles
Currently supports timeframes up to 1d (Daily). Weekly (1w) and Monthly (1M) are not yet supported.
This project is licensed under the MIT license. See the LICENSE file for more info.