Subscribe to prices for trading

The way you stream prices to your trading application will depend on the trade protocol selected for trades performed on individual components in the application.

Consider a trade tile component for trading FX products. When a trade is performed on a trade tile, it is normally a trade performed on Executable Streaming Prices (ESP trade protocol) which means that the prices for trading are streamed to the component before the trade is started. In such a case you should use the MessageService to subscribe to prices.

The MessageService creates subscriptions to subjects by attaching SubscriptionListener to them:

var oMessageService = caplin.core.ServiceRegistry.getService("caplin.message-service");
var sSubject = "/FX/GBPUSD";
oMessageService.subscribe(sSubject, oTileInstance);

The component processing the price updates must implement the SubscriptionListener interface and will receive data updates via the onDataUpdate() method callback:


TileObject.prototype.dataUpdated = function(sSubject, mData, mMetaData) {
  var buyRate = mData.BuyRate;
  var sellRate = mData.SellRate;
  // Update tile GUI with new rates

Alternatively, consider a trade ticket for performing forward trades on an FX product. The user must first select a settlement date and then request the prices to trade. The trade can also time out after a certain amount of time so the user will not be able to receive prices. In this case it is advisable to send the price updates from the server to the client via trade events which include the new price within the event data. To achieve this it is necessary to include a price update transition on the trade model.