Caplin Trader 5.1.0

Namespace: ct-alerts

ct-alerts

The alerts API defines the NotificationService and TriggerService interfaces.

Stubs that implement these interfaces are provided along with workbench tools that exercise the stubs. Fixtures are also provided so that Verifier acceptance tests can be written for components that use these services.

Notifications API

The NotificationService interface is an emitter as it is intended to notify its listeners of the following events defined in NotificationServiceEvents:

  • ADDED - when a new notification is added by the backend.
  • REMOVED - when a new notification is removed by the backend.
  • STATUS_CHANGED - when the notification service has become unavailable (or available).

The NotificationService provides a dismiss method so that components can dismiss notifications.

Note that notifications can arise from trigger conditions set by the user, such as a price reaching a certain point, but they can also come from other sources, such as a notification from the system that it will shut down.

A component could receive and dismiss a notification as follows:

var newNotification;
var notificationService = ServiceRegistry.getService('caplin.alerts.notification-service');
notificationService.on(NotificationServiceEvents.ADDED, function(notification) {
    newNotification = notification;
});

notificationService.dismiss(newNotification);

Triggers API

The TriggerService interface is an emitter as it is intended to notify its listeners of the following events defined in TriggerServiceEvents:

  • ADDED - when a new trigger is added by the backend.
  • REMOVED - when a trigger has been removed by the backend.
  • STATUS_CHANGED - when the trigger service has become unavailable (or available).

The TriggerService provides create and dispose methods so that components can create and dispose triggers.

A component could create a trigger and subsequently dispose it as follows:

var newTrigger;
var triggerService = ServiceRegistry.getService('caplin.alerts.trigger-service');
triggerService.on(TriggerServiceEvents.ADDED, function(trigger) {
    newTrigger = trigger;
});
triggerService.create(
    { subject: '/FX/GBPUSD', condition: 'BestBid > 1.7' },
    function() { alert 'error creating trigger'; }
);

triggerService.on(TriggerServiceEvents.REMOVED, function(trigger) { alert 'trigger with following subject removed: ' + trigger.getSubject(); }); triggerService.dispose(newTrigger, function() { alert 'error disposing trigger'; });