import {
DeepPartial,
HistogramData,
LineData,
LineWidth,
PriceScaleOptions,
SeriesDataItemTypeMap,
SeriesPartialOptionsMap,
SeriesType,
Time,
WhitespaceData,
} from 'lightweight-charts';
import { IndicatorDataFormatter, indicatorLabelById } from '@src/core/Indicators';
import { ChartSeriesType } from '@src/types/chart';
export enum IndicatorsIds {
Volume = 'vol',
SMA = 'sma',
EMA = 'ema',
MACD = 'macd',
}
export type IndicatorData = HistogramData<Time> | LineData<Time> | WhitespaceData<Time>;
export type IndicatorType = 'SMA' | 'EMA' | 'RSI' | 'OHLC' | 'VOL';
export type IndicatorSetting = NumberIndicatorSetting | SelectIndicatorSetting;
export type IndicatorSettings = Record<string, string | number>;
export type IndicatorLabel = (typeof indicatorLabelById)[IndicatorsIds];
export interface IndicatorStateConfig {
type: IndicatorType;
id?: IndicatorsIds;
period?: number;
color?: string;
lineWidth?: LineWidth;
visible?: boolean;
params?: Record<string, any>;
pane?: string;
}
interface BaseIndicatorSetting {
key: string;
label: string;
}
interface NumberIndicatorSetting extends BaseIndicatorSetting {
type: 'number';
defaultValue: number;
min?: number;
max?: number;
allowNegative?: boolean;
}
interface SelectIndicatorSetting extends BaseIndicatorSetting {
type: 'select';
defaultValue: string;
options: { label: string; value: string }[];
}
export interface IndicatorSerie {
id: string;
name: ChartSeriesType;
seriesOptions?: SeriesPartialOptionsMap[ChartSeriesType];
priceScaleOptions?: DeepPartial<PriceScaleOptions>;
priceScaleId?: string;
dataFormatter?<T extends SeriesType>(params: IndicatorDataFormatter<T>): SeriesDataItemTypeMap<Time>[T][];
}
export interface IndicatorConfig {
series: IndicatorSerie[];
settings?: IndicatorSetting[];
newPane?: boolean;
}