These chapters describe the creation of a simple CME application step-by step with samples.
Follow these instructions to get it to work:
- Initialize FIX engine
- Create MDApplication
- Subscribe to symbol
- Process incoming market data
- Unsubscribe from symbol
- Destroy MDApplication
- Destroy engine (release resources)
Execute the following instruction to initialize FIX engine.
The engine.properties file is required to read the engine configuration parameters. It must, by default, be present in the current directory. If the file is located elsewhere or has a different name specify the properties file name and path explicitly.
If an error occurs during initialization (the properties file is not found, a required property is missing etc.) the exception will be thrown.
You can create an MDApplication in three steps:
- Create Listener
- Configure MDApplications parameters
- Create an MDApplication object
- MDApplicationParams::templatesFn_ - Path to the CME FAST templates file. Should be downloaded from ftp://ftp.cmegroup.com
- MDApplicationParams::configXml_ - Path to the CME configuration file. Should be downloaded from ftp://ftp.cmegroup.com
Prior to calling createMDApplication, create a Listener, a class that implements Globex::MDApplicationListener interface. Usually this interface is implemented by classes that aggregate an MDApplication.
Subscribing and unsubscribing
You will start receiving market data from CME only after you subscribe to a symbol you want to receive. Use the MDApplication::subscribe(Symbol const& symbol) method for that:
The Listener will be notified about subscription by calling the MDApplicationListener::onSubscribed callback:
Use MDApplication::unsubscribe(Symbol const& symbol) method to unsubscribe from symbol:
When you unsubscribe from symbol, the engine calls the MDApplicationListener::onUnsubscribed( Globex::Symbol const& symbol ) notification method.
MDApplication::subscribeAll() and MDApplication::unsubscribeAll() methods are not implemented in the current version of FIX Antenna.
Processing incoming marketdata:
When MDApplication receives a message with market data, it calls one of the callback functions of the Listener object. A class should implement Globex::MDApplicationListener interface to be used as Listener:
- void onSubscribed() - called when successfully subscribed to symbol
- void onUnsubscribed() - called when successfully unsubscribed from symbol
- void onSnapshot() - called when a Market Data Snapshot Full Refresh (35=W) FIX message received.
- void onIncrement() - called when a Market Data Incremental Refresh (35=X) FIX Message received. According to FIX Messages specification, each incremental message can include information about several instruments. MDApplicationListener::onIncrement will be called separately for each instrument received.
- void onSecurityDefinition() - called when a Security Definition (35=d) FIX Message received.
- process() - called when any other FIX Message type received.
The Listener must be destroyed after MDApplication. It is recommended to turn a class-holder for MDApplication into the Listener. That will ensure a correct destruction order.
Use the MDApplication::release() method to release the resources consumed by MDApplication. Calling MDApplication::unsubscribe(const std::string& symbol) is optional.
The sample below illustrates all above mentioned instructions combined in one application.