This section describes the use of the Opentick input adapter. Opentick is an API and a service of opentick corporation to receive real-time stock market data, see http://www.opentick.com.
The Opentick input adapter is configured through a XML configuration file or directly through the ConfigurationOpentick class. The distribution provides a sample configuration file esperio-opentickadapter-config-sample.xml in the EsperIO etc folder.
There are two path available to start adapter operation: The first option is to register the adapter's plug-in loader and thus automatically load and start the adapter at time of Esper engine initialization. The second option requires your application to instantiate an OpentickInputAdapter.
This method loads the adapter automatically at time of engine initialization.
First, register the OpentickPluginLoader as one of the a plug-in loaders via the addPluginLoader method on the Configuration class or within the Esper configuration XML. For example:
Configuration config = new Configuration();
Properties pluginProperties = new Properties();
pluginProperties.put("classpath-app-context","esperio-opentickadapter-config-sample.xml");
config.addPluginLoader("OpentickPluginLoader",
OpentickPluginLoader.class.getName(), pluginProperties);
EPServiceProvider engine = EPServiceProviderManager.getDefaultProvider(config);At the time of engine initialization the loader class retrieves the XML configuration file from classpath and instantiates and starts the OpentickInputAdapter.
Your application may choose to use the OpentickInputAdapter class directly to start, stop, pause, resume and destroy the adapter separately from an Esper engine instance, or to configure via API and change the configuration at runtime.
This code snippet shows how to load a configuration file from a file location in the classpath and then starts the adapter:
ConfigurationOpentick configOT = new ConfigurationOpentick();
URL url = Thread.currentThread().
getContextClassLoader().getResource("esperio-opentickadapter-config-sample.xml");
if (url == null) {
throw new RuntimException("File not found");
}
configOT.configure(url);
OpentickInputAdapter adapter = new OpentickInputAdapter(configOT);
adapter.start();The opentick adapter XML and API configuration provides the connection information and the streams subscribed to in OT and defines symbol lists as well as associates symbol lists to streams. Please review the sample configuration file in the etc folder of the EsperIO distribution.
As part of the stream configuration your application may list the following stream names: OTQuote, OTMMQuote, OTTrade, OTBBO. The type-name attribute assigns an name to the opentick event types available in EPL statements. The event representation are the respective opentick API POJO objects: com.opentick.OTTrade and OTMMQuote, OTTrade, OTBBO.
The symbollists element serves to define named lists of exchange and symbol combinations. The stream-symbollist element associates symbols to streams requested through the opentick API.
The opentick adapter, once running, may be configured at runtime as well. To change symbol lists or request new streams at runtime, your application may obtain the ConfigurationOpentick from the adapter, make changes, and restart the adapter via its pause, resume, start, stop and destroy operations.
Use the pause or stop operation and the resume operation to retain the existing connection, drop streams and request new streams based on the new configuration. Use the destroy and start operations to disconnect and reconnect.