StockChart API

StockChart methods for loading OHLCV data, streaming candles, controlling ranges, and adding market layers.

Import
import { StockChart } from "@sixtyfold/stock";

Use the public entry point shown above.

ChartOverlayError

Error reported when one or more declarative overlay sources cannot be applied.

Import @sixtyfold/stockclass

class ChartOverlayError extends Error
MemberDefinitionDescription
cause?Error | undefinedCause for chart overlay error.
messagestringMessage text.
name"ChartOverlayError"Display name for this chart overlay error.
sourcesreadonly string[]Sources for chart overlay error.
stack?string | undefinedStack text.

ChartRendererError

Error reported when a chart renderer fails during startup or later use.

Import @sixtyfold/stockclass

class ChartRendererError extends Error
MemberDefinitionDescription
cause?Error | undefinedCause for chart renderer error.
messagestringMessage text.
name"ChartRendererError"Display name for this chart renderer error.
phaseRendererFailurePhasePhase for chart renderer error.
stack?string | undefinedStack text.

StockChart

Imperative browser chart for aggregated OHLCV candles, volume, analytics, profiles, price lines, and markers.

Import @sixtyfold/stockclass

class StockChart
MemberDefinitionDescription
addCandle(timestamp: number, open: number, high: number, low: number, close: number, volume: number) => voidQueues one OHLCV candle with a finite timestamp strictly after every queued or appended candle. Rapid calls batch through one animation frame; repeating a timestamp is not an update operation.
addCandleBatches(batches: readonly StockCandleBatch[], options?: StockAddCandlesOptions) => voidValidates all OHLCV chunks for equal column lengths and finite, strictly increasing timestamps across chunks and prior appends before flushing queued candles or transferring any buffer. Worker mode transfers valid buffers; main-thread mode retains the arrays by reference.
addCandles(timestamps: Float64Array, opens: Float64Array, highs: Float64Array, lows: Float64Array, closes: Float64Array, volumes: Float64Array, options?: StockAddCandlesOptions) => voidValidates six equally sized OHLCV columns and finite, strictly increasing timestamps after all queued or appended candles before flushing the queue. Invalid input preserves queued candles and caller buffers; worker mode transfers valid buffers and main-thread mode retains the arrays by reference.
batch(fn: () => void) => voidGroups synchronous appearance and viewport changes into one update. Nested batches are combined; data-loading calls still run immediately.
destroy() => voidReleases the chart and its owned resources.
getAppearance() => DeepReadonly<StockAppearanceOptions>Returns a read-only snapshot of the mutable appearance subset.
getOptions() => DeepReadonly<StockChartOptions>Returns a full normalized read-only snapshot of all options (construction + current appearance).
getRenderMode() => "worker" | "main"Returns the resolved rendering mode ("worker" or "main").
getViewport() => ViewportReturns a snapshot of the current viewport.
initialize() => Promise<void>Wait until the renderer is ready for data and runtime commands. The construction-time initialization watchdog rejects this promise with a ChartRendererError when the worker or main-thread fallback does not become ready in the configured interval. Applications should await this method before installing their first dataset.
initStreaming(maxCandles?: number) => voidAllocates a positive integer OHLCV ring-buffer capacity for live updates. Resets queued candles and timestamp ordering state and cancels the previous dataset's pending viewport animation.
reset(options?: { animated?: boolean; }) => voidReset the viewport to the full data extent.
resize() => voidSynchronizes the renderer with the canvas size.
setData(data: OHLCVData) => voidLoads six equally sized OHLCV columns with finite, monotonically ascending or descending timestamps, including equal timestamps, and normalizes the order. Worker mode transfers the normalized buffers; main-thread mode retains their arrays by reference. Replaces pending streaming samples and cancels the old viewport animation.
setIndicators(indicators: StockIndicator[]) => voidReplaces the built-in technical indicator definitions.
setKeyboardAnnouncements(messages: false | KeyboardAnnouncementMessages) => voidReplace or disable the localized keyboard-action announcements at runtime. Existing pending announcements are cancelled.
setLabels(labels: ChartLabels) => voidUpdate chart labels at runtime. Merges into existing labels (same semantics as updateAppearance). Throws: TypeError for malformed labels or sparse/non-object custom entries.
setMarkers(markers: StockMarker[]) => voidReplace all sparse timestamp/price markers.
setOverlay(overlay: OverlayOptions) => Promise<void>Update declarative overlay primitives at runtime. Valid primitives and successfully decoded images are installed even when another image fails. If every requested item fails, the previously rendered overlay remains installed. Resolution and renderer-delivery failures reject with ChartOverlayError; register setOverlayErrorCallback when the application also needs asynchronous notification. When called before the lazy renderer is ready, this promise includes the readiness wait. Superseded updates and chart destruction are routine cancellation and resolve without installing.
setOverlayErrorCallback(callback: OverlayErrorCallback | null) => voidRegister a callback for non-fatal overlay resolution or delivery failures. Successful overlay items are still installed. The matching setOverlay promise also rejects with the same error.
setPriceLines(priceLines: StockPriceLine[]) => voidReplace all horizontal data-anchored price levels.
setRendererErrorCallback(callback: RendererErrorCallback | null) => voidRegister a one-shot renderer failure callback. Called once before teardown for initialization or runtime failures. Without a callback, errors use console.error. Pass null to cancel it; destroy calls do not invoke it.
setStatsCallback(callback: ((stats: StockChartStats) => void) | null, options?: StockChartStatsOptions) => voidEnables renderer statistics and receives throttled snapshots. Pass null to disable them.
setTimeRange(range: TimeRange) => voidApplies one of the exported calendar/session presets. The chart does not render controls. Application-owned controls may call this method for a preset or setViewport() for any timestamp range.
setViewport(viewport: Partial<Viewport>, options?: { animated?: boolean; }) => voidSet a timestamp range. In market time, omitted edges resolve in the renderer after earlier requests, and getViewport() follows its accepted range sync.
setVolumeProfile(volumeProfile: VolumeProfileOptions | false) => voidReplace or disable the estimated candle-derived visible-range volume profile.
updateAppearance(patch: DeepPartial<BaseAppearanceOptions>) => voidPatch mutable appearance options at runtime. Throws: TypeError for malformed labels or sparse/non-object custom entries.