Kumo Charts

@kumo-charts/core/alert-engine

The API reference is generated from the source comments.

import { … } from '@kumo-charts/core/alert-engine';

Functions

createAlertEnginefunctionSource

function createAlertEngine(options: AlertEngineOptions = {}): AlertEngine

Evaluates alerts without a chart: give it the bars of a symbol at their source interval, the timeframe they are to be built to, the indicators and drawings its alerts read, and the alerts, and it reports each that fires, as a chart with the same would. Runs anywhere, Node included.

const engine = createAlertEngine({ indicators: [RSI] });
engine.data.set(bars, { interval: '1m' });
engine.data.setTimeframe('15m');
engine.indicators.add({ id: 'rsi', type: 'RSI' });
engine.alerts.add({ source: { kind: 'indicator', id: 'rsi' }, trigger: 'cross-up', value: 70 });
engine.on('alertTrigger', (event) => notify(event));
stream.onTrade((trade) => engine.data.addTrades(trade));

Interfaces

AlertEngineinterfaceSource

interface AlertEngine

Alerts evaluated without a chart, as a chart with the same bars, timeframe, indicators and drawings evaluates them: on a server, in a worker, or in a page for symbols no chart shows. Its data, indicators, drawings and alerts work as a chart's, but for what only drawing needs; an alert's event is never of a replay.

readonly data: Omit<DataApi, 'clear'>
readonly indicators: AlertEngineIndicators
readonly drawings: Pick<
  DrawingsApi,
  'set' | 'add' | 'remove' | 'get' | 'list' | 'validate' | 'levels'
>
readonly alerts: Omit<AlertsApi, 'clear'>
setCalendar(calendar: CalendarInput): void

Changes the trading calendar, as chart.applyOptions({ calendar }) does.

on<K extends keyof AlertEngineEventMap>(
  event: K,
  listener: (event: AlertEngineEventMap[K]) => void
): () => void

Listens to an event; returns the function that stops listening.

destroy(): void

Stops reporting and lets the engine go.

AlertEngineEventMapinterfaceSource

interface AlertEngineEventMap
alertTrigger: AlertTriggerEvent

AlertEngineIndicatorsinterfaceSource

interface AlertEngineIndicators extends Pick<
  IndicatorsApi,
  'add' | 'remove' | 'get' | 'list' | 'register' | 'definition'
>

What an engine computes alerts on: indicators as a chart has them, without drawing them.

valuesAt(id: string, index?: number): IndicatorOutputValue[]

The values of an indicator's outputs at displayed bar index; default, the latest bar.

AlertEngineOptionsinterfaceSource

interface AlertEngineOptions

Options of createAlertEngine.

readonly indicators?: readonly IndicatorDefinition[]

The indicator types its alerts may read, as the indicators module takes them, such as allIndicators; indicators.register() adds others. Default: none.

readonly drawings?: readonly DrawingTypeDefinition[]

The drawing types whose lines its alerts may watch, as the drawings module takes them, such as allDrawings. Default: none.

readonly calendar?: CalendarInput

The trading calendar timeframes are built and trades folded with, as the chart's calendar option. Default: around the clock, in UTC.

IndicatorOutputValueinterfaceSource

interface IndicatorOutputValue

The value of an output of an indicator at a bar, null where it has none.

readonly key: string
readonly value: number | null

↑↓ to select · Enter to open · Esc to close