The PriceTarget generator displays analyst price target lines (high, mean, low) on the chart for a given instrument.
Use a Controller object to add the generator to a chart:
const priceTargetGenerator = controller.addGenerator('PriceTarget');
type PriceTargetDataPoint = {
startDate: number,
endDate: number,
mean: number,
high: number,
low: number
};
type PriceTargetFetcher = (params: { instrument: string, currency?: string }) => Promise<PriceTargetDataPoint[]>;
startDate: timestamp marking the start of the price target periodendDate: timestamp marking the end of the price target periodmean: the average analyst price targethigh: the highest analyst price targetlow: the lowest analyst price targetThe generator emits the following events:
Type
interface PriceTargetGenerator {
emit(type: 'dataReady'): void;
}
Details
Emitted when price target data has been successfully loaded and applied to the chart.
Type
interface PriceTargetGenerator {
emit(type: 'priceRatingInfoClicked'): void;
}
Details
Emitted when the user clicks the "More info" button. Can be used to open a detailed view showing the price target and rating data.
The generator exposes several options to toggle which price target lines are displayed.
Type: boolean
Default: false
Details
When enabled, the high price target line is displayed.
Type: boolean
Default: false
Details
When enabled, the low price target line is displayed.
Type: boolean
Default: true
Details
When enabled, the mean price target line is displayed.
The generator exposes several public methods.
Type
declare class PriceTargetGenerator {
static setDataInterface(priceTargetFetcher: PriceTargetFetcher): void
}
Details
setDataInterface adds the callback to the generator which is required for loading data.
priceTargetFetcher is used to fetch price target data. The instrument and an optional currency will be passed to the function, which needs to return a PriceTargetDataPoint array.
Example
// example usage:
PriceTargetGenerator.setDataInterface(async ({ instrument, currency }) => {
const response = await fetch(`/api/pricetargets?instrument=${instrument}¤cy=${currency}`);
return response.json();
});
Type
interface PriceTargetGenerator {
setDataPoints(dataPoints: PriceTargetDataPoint[]): void;
}
Details
setDataPoints takes a PriceTargetDataPoint array and adds those to the chart. May be used as a simple alternative to the setDataInterface method, though this requires manual calling when the instrument or currency of the chart changes.
Example
// example usage:
priceTargetGenerator.setDataPoints([
{
startDate: 1700000000000,
endDate: 1703000000000,
mean: 150,
high: 180,
low: 120,
},
]);
The generator has a built-in permission check, which is called in its onStart method. It calls the provided checkPermission method (via Controller) with the key PriceTarget.