Apama Capital Markets Foundation Documentation : Capital Markets Foundation : Market Data Management : Market data subscribers : Setting subscription callbacks : Sample code for specifying callback when using handler to subscribe
Sample code for specifying callback when using handler to subscribe
After you obtain a subscriber object for a market data type, you can use that object to subscribe to receive market data and also specify the update callback to be executed when your application receives market data. If you previously added any callbacks to that subscriber handler (with the addUpdateCallback() action) they are not executed when your application receives data from this subscription. Only the specified update callback is executed when data is received.
Execute subscribeCb() for one symbol or multipleSubscribeCb() to receive data for more than one symbol. The following sample code shows a multiple subscription that specifies a callback. If there is an error that causes the subscription to fail then the specified update callback is ignored and the default error callback, or an error callback you added, is executed.
using com.apama.session.SessionHandlerFactory;
using com.apama.session.SessionHandler;
using com.apama.md.TradeSubscriberFactory;
using com.apama.md.TradeSubscriber;
 
monitor SubscriberExample7 {
 
context mainContext := context.current();
 
action onload() {
 
// Create and connect to the session
SessionHandler sessionHandler :=
(new SessionHandlerFactory).connect(
mainContext, "MySession", "MyTransport");
 
// Create the subscriber
TradeSubscriber subscriber :=
(new TradeSubscriberFactory).create( sessionHandler );
 
// Create a sequence of symbols and subscribe them
// and specify the update callback to be executed each time
// your application receives market data for this subscription
sequence< string > symbols := [ "EUR/USD", "EUR/GBP" ];
subscriber.multipleSubscribeCb(symbols, onAllTrade);
 
// Unsubscribe after 10 seconds and specify a callback
on wait ( 10.0 ) {
subscriber.multipleUnsubscribeCb(symbols, onUnsubscribe);
}
}
 
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;
}
 
action onUnsubscribe( TradeSubscriber subscriber,
com.apama.md.adapter.ConnectionKey connKey ) {
 
// This will be called for each symbol being unsubscribed
}
}
Note:  
If you execute addUnsubscribedCallback() on a subscriber handler and then execute unsubscribeCb() or multipleUnsubscribeCb() only the callback specified in the unsubscribe action is executed upon successful unsubscription. Any callbacks that were added with the addUnsubscribedCallback() action are ignored.
Copyright © 2013-2017 Software AG, Darmstadt, Germany. (Innovation Release)

Product LogoContact Support   |   Community   |   Feedback