Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

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)

Engine initialization

Execute the following instruction to initialize FIX engine.

 

Code Block
languagebash
// Initializes engine.
Engine::FixEngine::init();

 

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.

 

Code Block
languagebash
// Initializes engine.
Engine::FixEngine::init ("engine.properties");

 

If an error occurs during initialization (the properties file is not found, a required property is missing etc.) the exception will be thrown.

 

Code Block
languagebash
// Initializes engine.
try {
   Engine::FixEngine::init("engine.properties");
} 
catch( const Utils::Exception& ex ) {
   cout << "ERROR: " << ex.what() << endl;
}

 

MDApplication creation

You can create an MDApplication in three steps:

  • Create Listener
  • Configure MDApplications parameters
  • Create an MDApplication object

 

Code Block
languagebash
// Class Listener implements a MDApplicationListener interfaces
class Listener : public Globex::MDApplicationListener
{
   Globex::MDApplication* application_;
public:
   Listener() : application_(NULL) 
   {  
      // Initialize parameters   
      Globex::MDApplicationParams params;
      params.templatesFn_ = "templates.xml"; 
      params.configXml_ = "config.xml";  
      // Create MDApplication object    
      application_ = Engine::FixEngine::singleton()->createMDApplication( listener, params );
   }  
   // MDApplicationListener interface implementation
   // ...
};

 

  • 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:

 

Code Block
languagebash
application_->subscribe("ESZ8");

 

The Listener will be notified about subscription by calling the MDApplicationListener::onSubscribed callback:

 

Code Block
languagebash
Listner::onSubscribed( Globex::Symbol const& symbol ) {
   std::cout << "Subscribed on " << symbol << std::endl;
}

 

Use MDApplication::unsubscribe(Symbol const& symbol) method to unsubscribe from symbol:

 

Code Block
languagebash
application_->unsubscribe("ESZ8");

 

When you unsubscribe from symbol, the engine calls the MDApplicationListener::onUnsubscribed( Globex::Symbol const& symbol ) notification method.

 

Code Block
languagebash
Listner::onUnsubscribed( Globex::Symbol const& symbol ) {
   std::cout << "Unsubscribed from " << symbol  << std::endl;
}

 

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:

 

Code Block
languagebash
class MDApplicationListener
{
public:
    virtual void onSubscribed( Symbol const& symbol );
    virtual void onUnsubscribed( Symbol const& symbol );
    virtual void process( Engine::FIXMessage const& msg );
    virtual void onIncrement( Symbol const& symbol, Engine::TagValue const& entry ) = 0;
    virtual void onSnapshot( Symbol const& symbol, Engine::FIXMessage const& msg ) = 0;
    virtual void onSecurityDefinition( Symbol const& symbol, Engine::FIXMessage const& msg ) = 0;
    virtual ~MDApplicationListener();
};

 

  • 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.

Releasing resources

Use the MDApplication::release() method to release the resources consumed by MDApplication. Calling MDApplication::unsubscribe(const std::string& symbol) is optional.

Full sample

The sample below illustrates all above mentioned instructions combined in one application.

...