Apama 10.3 | Apama Capital Markets Foundation Documentation | Capital Markets Foundation | Market Data Management | Market data subscribers | Setting subscription callbacks | Sample code for specifying callback when using factory to subscribe
 
Sample code for specifying callback when using factory to subscribe
You can use a market data factory object to subscribe to receive market data and also specify a callback to execute when your application receives market data. The following code shows this. You can execute subscribeCb() for one symbol or multipleSubscribeCb() for more than one symbol. If there is an error that causes the subscription to fail then the specified update callback is ignored.
using com.apama.session.SessionHandlerFactory;
using com.apama.session.SessionHandler;
using com.apama.md.TradeSubscriberFactory;
 
monitor SubscriberExample6 {
 
context mainContext := context.current();
 
action onload() {
// Create and connect to the session
SessionHandler sessionHandler :=
(new SessionHandlerFactory).connect(
mainContext, "MySession", "MyTransport");
 
// Use a market data factory to subscribe and specify the
// update callback to be executed when data is received
(new TradeSubscriberFactory).subscribeCb(
sessionHandler, "SOW", onAllTrade);
}
 
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;
}
}

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.