Skip to content

API Reference


API Reference / CandleAggregator

Class: CandleAggregator

Defined in: src/ws/CandleAggregator.ts:35

Builds OHLCV candles in real time from WS ticks (ticker and full packets).

full packets carry Dhan's cumulative day volume rather than a per-print delta, so each bucket tracks the cumulative value observed at its first tick and reports cumulative - baseline as the bar's volume. A cumulative reading below the current baseline (day rollover, feed restart) re-bases rather than going negative.

This class holds no timers — callers own bucket-interval choice and must call flush/flushAll themselves (e.g. at session close) to emit the final in-progress bar for a security.

Extends

  • EventEmitter

Constructors

Constructor

new CandleAggregator(options?): CandleAggregator

Defined in: src/ws/CandleAggregator.ts:39

Parameters

options?

CandleAggregatorOptions = {}

Returns

CandleAggregator

Overrides

EventEmitter.constructor

Methods

handleTick()

handleTick(event): void

Defined in: src/ws/CandleAggregator.ts:45

Feed a parsed WS tick. No-ops for packet types without a price (OI, prev-close, disconnect).

Parameters

event

MarketFeedEvent

Returns

void


seed()

seed(exchangeSegment, securityId, candle, baselineVolume?): void

Defined in: src/ws/CandleAggregator.ts:94

Primes a bucket with a known candle, e.g. the latest bar from candlesFromSeries on connect.

Parameters

exchangeSegment

string

securityId

string

candle

Candle

baselineVolume?

number = 0

Returns

void


getCandle()

getCandle(exchangeSegment, securityId): Candle | undefined

Defined in: src/ws/CandleAggregator.ts:103

Current (possibly in-progress) candle for a security.

Parameters

exchangeSegment

string

securityId

string

Returns

Candle | undefined


flush()

flush(exchangeSegment, securityId): void

Defined in: src/ws/CandleAggregator.ts:108

Closes and removes the in-progress candle for one security, emitting close.

Parameters

exchangeSegment

string

securityId

string

Returns

void


flushAll()

flushAll(): void

Defined in: src/ws/CandleAggregator.ts:118

Closes and removes every in-progress candle, emitting close for each.

Returns

void


clear()

clear(): void

Defined in: src/ws/CandleAggregator.ts:125

Returns

void

Community project — not affiliated with Dhan. MIT License.