EPAM B2BITS MarketData C++ library  1.0.0
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages

Main features

API Reference

This section describes the creation of a simple GTP 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.
B2bits::MD::Engine::init ("gtp.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 %Lse::%Gtp::%Application

An instance of Lse::Gtp::Application is created using an XML configuration file. The configuration file defines adaptor options, services and service options.

application = B2bits::MD::Engine::singleton()->createGtpApplication(0, "GtpConfiguration.xml")

It is possible to have several instances of the Lse::Gtp::Application created at the same time. All the IO operations of all the services of an instance are processed by the same connection manager.

Opening the %Lse::%Gtp::%Application

Define your application listener class to handle application level events:

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

Open the instance of Lse::Gtp::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:

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

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 synchronization may be needed.

Connecting to market data

Define your service listener class to handle service level events:

class Level1ServiceListener : public Lse::Gtp::ServiceListener
{
virtual void onGtpMessage(Lse::Gtp::Service* service, const Lse::Gtp::MessageHeader* messageHeader, Lse::Gtp::PerformanceIndicator* performanceIndicator)
};
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 synchronization is needed.

Releasing resources

application must be destroyed using the Application::release method or using the delete operator. The ngine must be stopped using the method B2bits::MD::Engine::destroy()

Full example

#include <b2bits/Engine.h>
#include <B2BITS_GtpApplication.h>
#include <B2BITS_GtpService.h>
#include <iostream>
#include <stdexcept>
class ApplicationListener : public Lse::Gtp::ApplicationListener
{
public:
virtual void onServiceAdded(Lse::Gtp::Application* application, Lse::Gtp::Service* service)
{
// ...
}
virtual void onServiceRemoving(Lse::Gtp::Application* application, Lse::Gtp::Service* service)
{
// ...
}
};
class Level1ServiceListener : public Lse::Gtp::ServiceListener
{
public:
virtual void onReset(Lse::Gtp::Service* service, Lse::Gtp::ResetReason resetReason)
{
// ...
}
virtual void onGtpMessage(Lse::Gtp::Service* service, const Lse::Gtp::MessageHeader* messageHeader, Lse::Gtp::PerformanceIndicator* performanceIndicator)
{
// ...
}
};
int main()
{
try
{
// Engine initialization
try
{
// Group Ticker Plant Market Data Adaptor instantiation
Lse::Gtp::Application* application = B2bits::MD::Engine::singleton()->createGtpApplication(0, "GtpConfiguration.xml");
try
{
// Opening Group Ticker Plant Market Data Adaptor
ApplicationListener applicationListener;
application->open(&applicationListener);
try
{
Lse::Gtp::Service* level1Service = application->findService("Level 1");
if (! level1Service)
throw std::logic_error("Could not find service Level 1");
// Connecting to market data
Level1ServiceListener level1ServiceListener;
level1Service->connect(&level1ServiceListener);
try
{
// Waiting
std::string s;
std::cin >> s;
// Disconnecting from market data
level1Service->disconnect();
// Closing Group Ticker Plant Market Data Adaptor
application->close();
// Destroying Group Ticker Plant Market Data Adaptor
application->release();
// Destroying engine
return 0;
}
catch (...)
{
level1Service->disconnect();
throw;
}
}
catch (...)
{
application->close();
throw;
}
}
catch (...)
{
application->release();
throw;
}
}
catch (...)
{
throw;
}
}
catch (std::exception& exception)
{
std::cerr << "Error : " << exception.what() << std::endl;
return 1;
}
catch (...)
{
std::cerr << "Error" << std::endl;
return 1;
}
}
Lse::Gtp::ServiceListener
Definition: B2BITS_GtpService.h:249
Lse::Gtp::MessageHeader
Definition: B2BITS_LseGtpMessages.h:16
Lse::Gtp::Service::disconnect
virtual void disconnect()=0
Lse::Gtp::ResetReason
ResetReason
Definition: B2BITS_GtpTypes.h:66
B2bits::MD::Engine::destroy
static void destroy()
Lse::Gtp::ApplicationListener
Definition: B2BITS_GtpApplication.h:137
B2bits::MD::Engine::init
static Engine * init(InitParameters const &params)
B2bits::MD::Engine::createGtpApplication
Lse::Gtp::Application * createGtpApplication(Lse::Gtp::ConnectionManager *connectionManager, const std::string &configurationFilename)
Lse::Gtp::Application::findService
virtual Service * findService(const std::string &name)=0
Lse::Gtp::Application::open
virtual void open(ApplicationListener *applicationListener)=0
Lse::Gtp::PerformanceIndicator
Definition: B2BITS_GtpTypes.h:73
Lse::Gtp::Application::close
virtual void close()=0
B2bits::MD::Engine::singleton
static Engine * singleton()
Lse::Gtp::Service
Definition: B2BITS_GtpService.h:216
Lse::Gtp::Application
Definition: B2BITS_GtpApplication.h:88
Lse::Gtp::Application::release
virtual void release() const =0
Lse::Gtp::Service::connect
virtual void connect(ServiceListener *serviceListener)=0