Apama 10.3 | Apama Capital Markets Foundation Documentation | Capital Markets Foundation | Market Data Management | Market data subscribers | Setting subscription callbacks | Sample code for adding update callbacks to subscriptions
 
Sample code for adding update callbacks to subscriptions
After subscription to a market data type, your application begins to receive market data. If you want you can have one or more callback functions executed each time your application receives data. You do this by adding one or more update callbacks to the subscriber handler before subscription. The addition of update callbacks affects only subsequent subscriptions and not existing subscriptions.
Following is an example of adding an update callback to a subscriber handler:
using com.apama.session.SessionHandlerFactory;
using com.apama.session.SessionHandler;
using com.apama.md.TradeSubscriberFactory;
using com.apama.md.TradeSubscriber;
 
monitor SubscriberExample8 {
 
context mainContext := context.current();
 
action onload() {
SessionHandler sessionHandler :=
(new SessionHandlerFactory).connect(
"MySession", "MyTransport");
 
// Create a trade subscriber
TradeSubscriber tradeSubscriber :=
(new TradeSubscriberFactory).create(sessionHandler);
 
// Add an update callback and then subscribe
integer refId := tradeSubscriber.addUpdateCallback(onAllTrade);
tradeSubscriber.subscribe("SOW");
}
 
action onAllTrade( com.apama.md.client.CurrentTradeInterface currTrade ) {
log "Got Trade using Callback - " at INFO;
log " for symbol: " + currTrade.getSymbol() at INFO;
log " Quantity: " + currTrade.getQty().toString() at INFO;
log " Price: " + currTrade.getPrice().toString() at INFO;
log " With EP: " + currTrade.getEPValuesInterface().getRaw().toString()
at INFO;
}
}
Suppose you add one or more update callbacks to a subscriber handler and then execute the subscribeCb() or multipleSubscribeCb() action on that handler. MDA ignores the update callbacks that were previously added with the addUpdateCallback() action. Only the update callback specified in the subscribe action is invoked when new market data is received.

Copyright © 2013-2018 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.