Apama 10.3.1 | Apama Capital Markets Foundation Documentation | Capital Markets Foundation | Market Data Management | Market data subscribers | Subscribing to market data | Subscription examples | Sample code for using factory to subscribe
 
Sample code for using factory to subscribe
The simplest way to subscribe to market data is to execute the subscribe() or multipleSubscribe() actions on a factory instance for the type of market data you are interested in. After a successful subscription to market data, your application starts receiving market data events. Often, you set up listeners for the events of interest and specify actions to be performed when there is a match. For example:
using com.apama.session.SessionHandlerFactory;
using com.apama.session.SessionHandler;
using com.apama.md.TradeSubscriberFactory;
 
monitor SubscriberExample1 {
 
context mainContext := context.current();
 
action onload() {
// Create and connect the session handler
SessionHandler sessionHandler :=
SessionHandlerFactory.connect(
mainContext, "MySession", "MyTransport");

// Create the trade subscriber factory and specify the session
// handler plus a symbol to subscribe
TradeSubscriber subscriber :=
TradeSubscriberFactory.subscribe(sessionHandler, "SOW");

on all com.apama.md.T() {
// Process the trade
}
}
}
Execution of the xxxSubscriberFactory.subscribe() or multipleSubscribe() actions creates a subscription for receiving market data. In the previous example, note that the subscribe() action returns a TradeSubscriber object. You need a TradeSubscriber object if you want to do any of the following:
*Add one or more callbacks. The default behavior for successful subscription to market data does not invoke any callback functions. You might want to change this so that your application executes some logic upon a successful subscription, or when it receives data, or when it unsubscribes. See Setting subscription callbacks.
*Set one or more subscription parameters. See Setting subscription parameters.
*Override default error behavior. By default, a failed subscription invokes a common error callback, which logs messages at the ERROR level. See Overriding default error handling for subscriptions.

Copyright © 2013-2019 | 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.