Sample code for subscription update callback invoked in a connection callback
You can define a connection callback in which you subscribe to market data and specify an update callback on the subscription. For example:
using com.apama.session.SessionHandlerFactory;
using com.apama.session.SessionHandler;
using com.apama.md.DepthSubscriberFactory;
using com.apama.md.DepthSubscriber;
using com.apama.md.client.CurrentDepthInterface;
using com.apama.oms.NewOrder;
using com.apama.oms.OrderUpdate;
monitor SubscriberExample11 {
context mainContext := context.current();
action onload() {
// Connect to a session and specify callback
SessionHandlerFactory().create(mainContext).connectCb(
"MySession", "MyTransport", onSessionConnected);
}
action onSessionConnected(SessionHandler sessionHandler) {
// Subscribe to depth updates for single symbol
DepthSubscriberFactory().create(sessionHandler).
subscribeCb("SOW",onDepth);
}
action onDepth(CurrentDepthInterface di) {
// Report updates
log "Got Depth update using Callback - " at INFO;
log " Symbol: " + di.getSymbol() at INFO;
log " Best Bid Quantity: " + di.getBBA().getBidQty().
toString() at INFO;
log " Best Bid Price: " + di.getBBA().getBidPrice().
formatFixed(2) at INFO;
log " Best Ask Quantity: " + di.getBBA().getAskQty().
toString() at INFO;
log " Best Ask Price: " + di.getBBA().getAskPrice().
formatFixed(2) at INFO;
}
}