Apama Capital Markets Foundation Documentation : Capital Markets Foundation : Market Data Management : Market data subscribers : Subscribing to market data : Subscription examples : Sample code for using multiple contexts to receive market data
Sample code for using multiple contexts to receive market data
When using MDA, when you call an action that takes a context as a parameter you must specify a reference to the main context. However, you can use multiple contexts to receive and operate on market data. The following code provides an example of using multiple contexts.
using com.apama.session.SessionHandlerFactory;
using com.apama.session.SessionHandler;
using com.apama.md.TradeSubscriberFactory;
using com.apama.md.TradeSubscriber;
using com.apama.md.client.CurrentTradeInterface;
monitor SubscriberExample3 {
action onload() {
context mainContext := context.current();
// Spawn to a separate context for each symbol
spawn init(mainContext,"SYM1") to context("SYM1");
spawn init(mainContext,"SYM2") to context("SYM2");
spawn init(mainContext,"SYM3") to context("SYM3");
action init(context mainContext, string symbol) {

// Connect to a session
SessionHandler sessionHandler := SessionHandlerFactory.connect(
mainContext, "MySession", "MyTransport");

// Subscribe to depth updates for each context's symbol.
// This is a way to use the factory to subscribe
// without returning a subscriber object.
// Process the trade
on all com.apama.md.T() {
Copyright © 2013-2017 Software AG, Darmstadt, Germany. (Innovation Release)

Product LogoContact Support   |   Community   |   Feedback