EPAM B2BITS C++ Mit MarketData handler  1.25.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Quick Start

API Reference

This section describes the creation of a simple MIT application step by step.
Follow these instructions to get it to work:

Engine initialization

Execute the following instruction to initialize market data 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.

// Initializes engine.
Engine::init ("mit.app.properties");

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

Creating Mit:Application

Instance of Mit::Application can be created in two ways:

Mit::ApplicationOptions applicationOptions;
applicationOptions.fixDictionaryFilename = "fixdic50sp2jse.xml";
...
set other app properties
...
application = B2bits::MD::Engine::singleton()->createMitApplication(0, "JSE", applicationOptions);

It is possible to have several instances of Mit::Application created at the same time. All the IO operations of all the services of an instance are processed by the same connection manager. A typical solution is to have a dedicated instance for each market (LSE, JSE, NSX).

Opening Mit:Application

Define your application listener class to handle application level events:

class ApplicationListener : public Mit::ApplicationListener
{
virtual void onServiceAdded(Mit::Application* application, Mit::Service* service);
virtual void onServiceRemoving(Mit::Application* application, Mit::Service* service)
};
ApplicationListener applicationListener;

Open the instance Mit::Application and specify a pointer to your application listener instance: application->open(&applicationListener);

If the XML configuration file was used, the services defined in it are created and added automatically. You can iterate through them or find a specific service by name:

Mit::Service* service = application->findService("Level 1");
if (!level1Service)
throw std::logic_error("Could not find service Level 1");

If the XML configuration file was not used, use must define and add services explicitly:

Mit::ServiceOptions level1ServiceOptions;
level1ServiceOptions.fastTemplateFilename = "MIT_FAST_Templates_JSE_FAST_v_4.0.0.0.xml";
...
other properties
...
Mit::Service* service = application->addService(Mit::stFast, "Level 1", level1ServiceOptions);

The application listener is notified on events from the client thread - no synchronization is needed. However, if the same application listener is shared with several applications it may be notified from different concurrent client threads and a synchronization may be needed.

Connecting to market data

Define your service listener class to handle service level events:

class Level1ServiceListener : public Mit::ServiceListener
{
virtual void onFixMessage(Mit::Service* service, B2bits::MD::FIXMessage* message, Mit::PerformanceIndicator* pi)
};
Level1ServiceListener level1ServiceListener;

Connect the service to the market data and specify a pointer to your service listener instance:

service->connect(&level1ServiceListener);

The service listener is notified on events from different non-concurrent threads - no synchronization is needed. However, if the same service listener is shared with several services it can be notified from different concurrent threads and a synchronization is needed.

Releasing resources

application must be destroed using Application::release method or using delete operator. engine must be stopped using B2bits::MD::Engine::destroy()

Full example

#include <b2bits/Engine.h>
#include <B2BITS_MitApplication.h>
#include <B2BITS_MitService.h>
#include <iostream>
#include <memory>
#include <stdexcept>
class ApplicationListener : public Mit::ApplicationListener
{
virtual void onServiceAdded(Mit::Application* application, Mit::Service* service)
{
// ...
}
virtual void onServiceRemoving(Mit::Application* application, Mit::Service* service)
{
// ...
}
};
class Level1ServiceListener : public Mit::ServiceListener
{
virtual void onReset(Mit::Service* service, Mit::ResetReason resetReason)
{
// ...
}
virtual void onFixMessage(Mit::Service* service, B2bits::MD::FIXMessage* message, Mit::PerformanceIndicator* performanceIndicator)
{
// ...
};
virtual void onItchMessage(Mit::Service* service, const Jse::Itch::MessageHeader* messageHeader, Mit::PerformanceIndicator* performanceIndicator)
{
// ...
}
};
int main()
{
try
{
// Engine initialization
// MilleniumIT Market Data Adaptor instantiation
bool useConfigurationFile = true;
std::auto_ptr<Mit::Application> application;
if (useConfigurationFile) {
application.reset(B2bits::MD::Engine::singleton()->createMitApplication(0, "JseConfiguration.xml"));
}
else {
Mit::ApplicationOptions applicationOptions;
applicationOptions.fixDictionaryFilename = "fixdic50sp2jse.xml";
// ...
application.reset(B2bits::MD::Engine::singleton()->createMitApplication(0, "JSE", applicationOptions));
}
// Opening MilleniumIT Market Data Adaptor
ApplicationListener applistener;
application->open(&applistener);
Mit::Service* level1Service;
if (useConfigurationFile) {
level1Service = application->findService("Level 1");
if (!level1Service)
throw std::logic_error("Could not find service Level 1");
}
else {
Mit::ServiceOptions level1ServiceOptions;
level1ServiceOptions.fastTemplateFilename = "MIT_FAST_Templates_JSE_FAST_v_4.0.0.0.xml";
// ...
level1Service = application->addService(Mit::stFast, "Level 1", level1ServiceOptions);
}
// Connecting to market data
Level1ServiceListener level1ServiceListener;
level1Service->connect(&level1ServiceListener);
std::cout << "Listening to market data...";
std::string s;
std::cin >> s;
}
catch (std::exception& exception)
{
std::cerr << "Error : " << exception.what() << std::endl;
}
// Destroying engine
return 0;
}