Apama Capital Markets Foundation Documentation : Capital Markets Foundation : Market Data Management : Basic example of working with market data
Basic example of working with market data
The following code provides a basic example of how to work with market data. It assumes that an adapter has already been set up and that you know that the session ID for that adapter is MySession and that the transport ID for that adapter is MyTransport. While code can be in multiple contexts, when you execute an MDA action that requires a reference to a context, the reference must be to the main context.
using com.apama.session.SessionHandlerFactory;
using com.apama.session.SessionHandler;
using com.apama.md.TradeSubscriberFactory;
using com.apama.md.TradeSubscriber;
monitor SimpleTradeExample {
action onload() {
// Connect to a market data source
SessionHandler sessionHandler :=
(new SessionHandlerFactory).connect(
context.current(),"MySession", "MyTransport");
// Subscribe to trades on market data source
TradeSubscriber tradeSubscriber :=
(new TradeSubscriberFactory).subscribe(sessionHandler,"SOW");
com.apama.md.T trade;
on all com.apama.md.T():trade {
emit trade;
To run this code, you can configure the correlator to use the CMF market data simulator or an external MDA adapter, and substitute the appropriate session and transport identifiers and subscription symbol. For a fully working example, see the samples folder in your CMF installation directory.
Subscriber objects must be initialized by a factory object before they can be used. For example, the following code does not work:
monitor InvalidTradeExample {
context mainContext := context.current();
com.apama.session.SessionHandler sessionHandler;
com.apama.md.TradeSubscriber tradeSubscriber;
action onload() {
// This will not work:
sessionHandler.connect(mainContext, "MySession", "MyTransport");
Copyright © 2013-2017 Software AG, Darmstadt, Germany. (Innovation Release)

Product LogoContact Support   |   Community   |   Feedback