@dxfeed/dxlink-indichart
Version:
dxLink INDICHART for receiving candle and indicator data
151 lines (150 loc) • 6.73 kB
TypeScript
import { type DXLinkChannel, DXLinkChannelState, type DXLinkChannelStateChangeListener, type DXLinkClient, DXLinkLogLevel } from '@dxfeed/dxlink-core';
import { type DXLinkIndiChartCandle, type DXLinkIndiChartConfig, type DXLinkIndiChartIndicators, type DXLinkIndiChartIndicatorsParameters, type DXLinkIndiChartIndicatorsData, type DXLinkIndiChartSetup, type DXLinkIndiChartSubscription, type DXLinkIndiChartIndicatorsStates } from './messages';
export type DXLinkIndiChartUpdateListener = (candles: DXLinkIndiChartCandle[], indicators: DXLinkIndiChartIndicatorsData, pending: boolean) => void;
export type DXLinkIndiChartCandleSnapshotListener = (candles: DXLinkIndiChartCandle[], reset: boolean, pending: boolean) => void;
export type DXLinkIndiChartIndicatorsSnapshotListener = (indicators: DXLinkIndiChartIndicatorsData, pending: boolean) => void;
export type DXLinkIndiChartIndicatorsStateListener = (indicators: DXLinkIndiChartIndicatorsStates) => void;
export interface DXLinkIndiChartSubscriptionState {
subscription: DXLinkIndiChartSubscription;
indicatorsParameters: DXLinkIndiChartIndicatorsParameters;
}
/**
* dxLink Chart service.
*/
export interface DXLinkIndiChartRequester {
/**
* Unique identifier of the Chart channel.
*/
readonly id: number;
/**
* Get current channel of the Chart.
* Note: inaproppriate usage of the channel can lead to unexpected behavior.
* @see {DXLinkChannel}
*/
getChannel(): DXLinkChannel;
setSubscription(subscription: DXLinkIndiChartSubscription, indicatorsParameters: DXLinkIndiChartIndicatorsParameters): void;
getSubscription(): DXLinkIndiChartSubscriptionState | null;
setup(setup: DXLinkIndiChartSetup): void;
getConfig(): DXLinkIndiChartConfig | null;
getIndicators(): DXLinkIndiChartIndicatorsStates | null;
/**
* Add a listener for the Chart data updates (INDICHART_UPDATE).
*/
addUpdateListener(listener: DXLinkIndiChartUpdateListener): void;
/**
* Remove a listener for the Chart data updates.
*/
removeUpdateListener(listener: DXLinkIndiChartUpdateListener): void;
/**
* Add a listener for the Chart candle snapshots (INDICHART_CANDLE_SNAPSHOT).
*/
addCandleSnapshotListener(listener: DXLinkIndiChartCandleSnapshotListener): void;
/**
* Remove a listener for the Chart candle snapshots.
*/
removeCandleSnapshotListener(listener: DXLinkIndiChartCandleSnapshotListener): void;
/**
* Add a listener for the Chart indicator snapshots (INDICHART_INDICATORS_SNAPSHOT).
*/
addIndicatorsSnapshotListener(listener: DXLinkIndiChartIndicatorsSnapshotListener): void;
/**
* Remove a listener for the Chart indicator snapshots.
*/
removeIndicatorsSnapshotListener(listener: DXLinkIndiChartIndicatorsSnapshotListener): void;
/**
* Add a listener for the Chart indicators state changes received from the channel.
*/
addIndicatorsStateChangeListener(listener: DXLinkIndiChartIndicatorsStateListener): void;
/**
* Remove a listener for the Chart indicators state changes received from the channel.
*/
removeIndicatorsStateChangeListener(listener: DXLinkIndiChartIndicatorsStateListener): void;
/**
* Close the Chart channel.
*/
close(): void;
}
/**
* Options for the {@link DXLinkIndiChart} instance.
*/
export interface DXLinkIndiChartOptions {
/**
* Log level for the Chart.
*/
logLevel: DXLinkLogLevel;
}
/**
* dxLink Indi Chart service implementation.
*/
export declare class DXLinkIndiChart implements DXLinkIndiChartRequester {
/**
* Unique identifier of the Chart channel.
*/
readonly id: number;
private readonly updateListeners;
private readonly candleSnapshotListeners;
private readonly indicatorsSnapshotListeners;
private readonly indicatorsStateListeners;
private readonly logger;
private readonly channel;
private lastSubscriptionState;
private lastSetup;
private lastConfig;
private indicators;
/**
* Allows to create {@link DXLinkIndiChart} instance with the specified {@link ChartContract} for the given {@link DXLinkWebSocketClient}.
*/
constructor(client: DXLinkClient, indicators: DXLinkIndiChartIndicators);
getChannel: () => DXLinkChannel;
getState: () => DXLinkChannelState;
addStateChangeListener: (listener: DXLinkChannelStateChangeListener) => void;
removeStateChangeListener: (listener: DXLinkChannelStateChangeListener) => void;
addIndicatorsStateChangeListener: (listener: DXLinkIndiChartIndicatorsStateListener) => Set<DXLinkIndiChartIndicatorsStateListener>;
removeIndicatorsStateChangeListener: (listener: DXLinkIndiChartIndicatorsStateListener) => boolean;
setup: (setup: DXLinkIndiChartSetup) => void;
getConfig: () => DXLinkIndiChartConfig | null;
getIndicators: () => DXLinkIndiChartIndicatorsStates | null;
close: () => void;
setSubscription: (subscription: DXLinkIndiChartSubscription, indicatorsParameters: DXLinkIndiChartIndicatorsParameters) => void;
getSubscription: () => DXLinkIndiChartSubscriptionState | null;
removeIndicators: (indicators: string[]) => void;
addUpdateListener: (listener: DXLinkIndiChartUpdateListener) => void;
removeUpdateListener: (listener: DXLinkIndiChartUpdateListener) => void;
addCandleSnapshotListener: (listener: DXLinkIndiChartCandleSnapshotListener) => void;
removeCandleSnapshotListener: (listener: DXLinkIndiChartCandleSnapshotListener) => void;
addIndicatorsSnapshotListener: (listener: DXLinkIndiChartIndicatorsSnapshotListener) => void;
removeIndicatorsSnapshotListener: (listener: DXLinkIndiChartIndicatorsSnapshotListener) => void;
/**
* Process message received in the channel.
*/
private processMessage;
/**
* Process data updates received from the channel.
*/
private processUpdate;
/**
* Process candle snapshot received from the channel.
*/
private processCandleSnapshot;
/**
* Process indicators snapshot received from the channel.
*/
private processIndicatorsSnapshot;
/**
* Process channel status changes from the channel.
*/
private processStatus;
/**
* Process error received from the channel.
*/
private processError;
/**
* Reconfigure the CHART channel after the channel re-open.
*/
private reconfigure;
/**
* Updates the indicators parameters without changing the subscription.
* @param indicatorsParameters New indicators parameters.
*/
updateIndicatorsParameters: (indicatorsParameters: DXLinkIndiChartIndicatorsParameters) => void;
}