GTP Market Data Adapter. Quick Start Guide
This section describes how to use the Group Ticker Plant Market Data Adapter in a step-by-step fashion.
The main steps include:
- Engine Initialization
- Group Ticker Plant Market Data Adaptor Instantiation
- Opening Group Ticker Plant Market Data Adaptor
- Connecting to Group Ticker Plant Market Data
- Disconnecting from Group Ticker Plant Market Data
- Closing Group Ticker Plant Market Data Adaptor
- Destroying Engine
Engine Initialization
B2bits::MD::Engine::init();
Group Ticker Plant Market Data Adaptor Instantiation
A user can create an instance of the Group Ticker Plant Market Data Adaptor using an XML configuration file. The configuration file defines adaptor options, services and service options.
Lse::Gtp::Application* application = B2bits::MD::Engine::singleton()->createGtpApplication(0, "GtpConfiguration.xml");
It is possible to have several Application instances created at the same time. The same connection manager processes all the IO operations of all the services of the Application instance.
Opening Group Ticker Plant Market Data Adaptor
Define your application listener class to handle the Group Ticker Plant Market Data Adaptor application-level events:
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) Â Â Â { Â Â Â Â Â Â Â // ... Â Â Â } }; ApplicationListener applicationListener;
Open the instance of the Group Ticker Plant Market Data Adaptor and specify a pointer to your application listener instance:
application->open(&applicationListener);
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* level1Service = 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 Group Ticker Plant Market Data
Define your service listener class to handle service-level events:
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) Â Â Â { Â Â Â Â Â Â Â // ... Â Â Â } }; Level1ServiceListener level1ServiceListener;
Connect the service to the market data and specify a pointer to your service listener instance:
level1Service->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.
Disconnecting from Group Ticker Plant Market Data
Disconnect the service from the market data to stop getting the service level events:
level1Service->disconnect();
Closing Group Ticker Plant Market Data Adaptor
Close the Group Ticker Plant Market Data Adaptor instance to free resources used by the instance:
application->close();
Destroying Group Ticker Plant Market Data Adaptor
Destroy the Group Ticker Plant Market Data Adaptor instance:
application->release();
Destroying Engine
B2bits::MD::Engine::destroy();
Full Sample
#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        B2bits::MD::Engine::init();        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                        B2bits::MD::Engine::destroy();                        return 0;                    }                    catch (...)                    {                        level1Service->disconnect();                        throw;                    }                }                catch (...)                {                    application->close();                    throw;                }            }            catch (...)            {                application->release();                throw;            }        }        catch (...)        {            B2bits::MD::Engine::destroy();            throw;        }    }    catch (std::exception& exception)    {        std::cerr << "Error : " << exception.what() << std::endl;        return 1;    }    catch (...)    {        std::cerr << "Error" << std::endl;        return 1;    } }