Use a Controller object to add the generator to a chart:
const alertsGenerator = controller.addGenerator('Alerts');
All alerts passed to the generator must already be filtered and adjusted to the selected exchange in the chart.
type Alert = {
comment?: string | null;
id: string;
ts: number;
value: number;
referenceId?: string | null;
commentPrefix?: string | null;
validUntil?: number | null;
}
comment
: optional comment set by the userid
: unique id of the alertts
: timestamp of the creation of the alert. Will be used to show the user in the chart when it was createdvalue
: value of the alert. Will be used to show the user where the alert is placedreferenceId
: id of another alert. Can be used to submit changes for a specific alert to the generator. The new Id will replace the referenced one. Will only work if the referenced alert still exists in the generator.commentPrefix
: string that will be placed before the user comment, e.g. Kursalarm PREFIX: My Custom Comment
.validUntil
: timestamp that the alert is valid untilThe generator emits several different events:
Type
interface Alerts {
emit(type: 'changeAlert', alert: {
id: string,
value: number,
comment: string,
}): void;
}
Details
Emitted when the user changes the value or the comment of an existing alert. Emits an object containing the id of the alert as well as the value and the comment.
Example
// example usage:
alertsGenerator.on('changeAlert', (alert) => {
/* alert
* {
* id: '1845666989'
* comment: 'test'
* value: 500
* }
*/
});
Type
interface Alerts {
emit(type: 'deleteAlert', alert: Alert): void;
}
Details
Emitted when the user presses the Delete
button of an alert, or selects Delete
in the context action menu. Alerts still need to be manually removed from the chart by calling alertsGenerator.removeAlert(alert)
.
Example
// example usage:
alertsGenerator.on('deleteAlert', (alert) => {
/* alert
* {
* id: '18616816858',
* value: 500,
* comment: 'test',
* }
*/
});
Type
interface Alerts {
emit(type: 'manageAlerts'): void;
}
Details
Emitted when the user clicks on the settings button to open the alert manager widget.
Example
// example usage:
alertsGenerator.on('manageAlerts', () => {});
Type
interface Alerts {
emit(type: 'newAlert'): void;
}
Details
Emitted when the user clicks on the settings button to create a new alert.
Example
// example usage:
alertsGenerator.on('newAlert', () => {});
Type
emit(type: 'showIndicatorAlerts'): void;
Details
Emitted when the user clicks on the settings button to open indicator alerts.
Example
// example usage:
alertsGenerator.on('showIndicatorAlerts', () => {});
The generator exposes several public methods.
Type
interface Alerts {
static visualizeValidity(visualize: boolean): void
}
Details
By default, the alert line will beginn at the timestamp of creation of the alert (ts
), and end at the timestamp of the validity (validUntil
), or, if null, the right side of the chart. In some cases, it may be preferable to always extend the line to the right, regardless of the validity. This can be set by using this static method.
Type
interface Alerts {
setAlert(alert: Alert): AlertsTool | null;
}
Details
setAlert
takes an Alert
object, which requires the properties id
, ts
and value
to be set. Objects without any of these properties will generate a warning. It will return the tool, or null if the tool could not be created.
Type
interface Alerts {
setAlerts(alerts: Array<Alert>): Array<AlertsTool | null>;
}
Details
setAlerts
works similarly, but takes an Array<Alert>
instead. Alerts in the array without the required properties will trigger warnings. It will return an Array with the tools or null at their specific position.
Type
interface Alerts {
removeAlert(alert: Pick<Alert, 'id'>): void;
}
Details
removeAlert
takes an Alert
object, in which only the ID property must be present, and removes the alert line identified by said ID from the chart.
Type
interface Alerts {
getPrecision(): number;
}
Details
getPrecision
returns the precision of the chart.
Type
interface Alerts {
getExchangeId(): number | undefined;
}
Details
getExchangeId
returns the exchange Id present in the chart or undefined if no exchange is present.
Type
interface Alerts {
getInstrumentId(): number | undefined;
}
Details
getInstrumentId
returns the Id of the instrument present in the chart or undefined, if no instrument is present.
Type
interface Alerts {
getCurrency(): string;
}
Details
getCurrency
returns the currency of the chart or 'N/A' if none is available.
Type
interface Alerts {
getAlert(): Alert
}
Details
getAlert
returns the alert of the tool
Type
interface Alerts {
set('delete'): void
}
Details
Appears as a button in the UI. Emits the deleteAlert
event
Type
interface Alerts {
get('comment'): string
set('comment', value: string): void
}
Details
Gets/sets the user comment for the specific alert.
Type
interface Alerts {
get('descriptionAlignment'): 'right' | 'bottom-right' | 'left' | 'bottom-left'
set('descriptionAlignment', value: 'right' | 'bottom-right' | 'left' | 'bottom-left'): void
}
Details
Gets/sets the comment alignment, denoting whether it should be above or below the alert line. To change between above and below the line, use right
and bottom-right
.
The Alerts Generator has two optional settings buttons that are hidden by default: "manageAlerts" and "showIndicatorAlerts". The former should be used to open a quote alert management tool, while the latter should be used to open an indicator alert management tool. These are disabled by default as they may not be relevant for all platforms. To enable one of these buttons, you will have to set the exposed flag to true.
// examples
utils.addOptionFlag(alertsGenerator, 'manageAlerts', ObjectEOptionFlags.EXPOSED);
utils.addOptionFlag(alertsGenerator, 'inda', ObjectEOptionFlags.EXPOSED); // belongs to the showIndicatorAlerts event