Caplin Trader 5.1.0

Namespace: ct-watchlist

ct-watchlist

The watchlist package provides interface definitions for the WatchlistService, Watchlist and WatchlistContentsManager.

The module:ct-watchlist/WatchlistService handles creation, disposal and retrieval of watchlists. The module:ct-watchlist/Watchlist represents a watchlist, provides access to metadata and generates a module:ct-watchlist/WatchlistContentsManager, which provides access to the watchlist contents.

Stubs that implement these interfaces are provided along a service fixture enabling Verifier acceptance tests to be written for components that use these services.

Watchlist API

The WatchlistService interface is an emitter that notifies any listeners of the following events defined in ct-watchlist/WatchlistServiceEvents:

  • ADDED - when a new watchlist is added.
  • REMOVED - when a watchlist has been removed.
  • STATUS_CHANGED - when the watchlist service's availability changes, assuming one of the values in module:ct-services/ServiceStatus.

The WatchlistService provides create and dispose methods so that components can create and dispose watchlists. Note that create takes a name string to create a single watchlist, and dispose takes an array of Watchlist objects, so it can dispose multiple watchlists at once.

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

var WatchlistServiceEvents = require('ct-watchlist/WatchlistServiceEvents');
var newWatchlist;
var watchlistService = ServiceRegistry.getService('caplin.watchlist.watchlist-service');
watchlistService.on(WatchlistServiceEvents.ADDED, function(watchlist) {
    newWatchlist = watchlist;
    alert('watchlist with following name has been added: ', watchlist.getName());
});

var errorCallback = function() { alert('error creating watchlist'); } watchlistService.create( 'FX Majors', errorCallback );

watchlistService.on(WatchlistServiceEvents.REMOVED, function(watchlist) { alert('watchlist with following subject removed: ' + watchlist.getSubject()); }); watchlistService.dispose([ newWatchlist ], function() { alert('error disposing watchlist'); });

A component could disable itself when the WatchlistService becomes unavailable as follows:

var ServiceStatus = require('ct-services/ServiceStatus');
var WatchlistServiceEvents = require('ct-watchlist/WatchlistServiceEvents');
watchlistService.on(WatchlistServiceEvents.STATUS_CHANGED, function(status) {
    if(status !== ServiceStatus.AVAILABLE) {
        disableComponent();
    }
});