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

API Reference


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

Engine initialization

Execute the following instruction to initialize FIX engine.

// Initializes engine.
Engine::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.

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

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

// Initializes engine.
try {
Engine::init("engine.properties");
}
catch( const std::exception& ex ) {
cout << "ERROR: " << ex.what() << endl;
}

BovespaApplication creation

You can create an BovespaApplication in three steps:

Configure BovespaApplication parameters, create BovespaApplication object.

// Initialize parameters
BovespaApplicationParams params;
// XML configs
params.templatesFn_ = "templates.xml";
params.configXml_ = "config.xml";
// TCP Replay parameters
params.tcpReplayParams_.senderCompId_ = "Sender";
params.tcpReplayParams_.targetCompId_ = "Target";
params.tcpReplayParams_.username_ = "username";
params.tcpReplayParams_.password_ = "12345";
params.tcpReplayParams_.ip_ = "1.2.3.4;";
params.tcpReplayParams_.port_ = 3001;
// Create Application object
app_ = Engine::FixEngine::singleton()->createBovespaApplication(params);

Subscription

You will start receiving market data from after you subscribe to a symbol and provide per-instrument listener.

Use the BovespaApplication::subscribeToInstrument method for that.
Market data will be delivered to the listener's callbacks.

BovespaSubscriptionItem item;
item.symbol_ = symbol;
app_->subscribeToInstrument(item, new PerInstrumentListener());

Releasing resources

Use the BovespaApplication::release() method to release the resources. Calling unsubscribe is optional.

Full example

#include <iostream>
#include <string>
#include <b2bits/Engine.h>
#include <B2BITS_BovespaApplication.h>
#include <B2BITS_BovespaApplicationListeners.h>
using namespace Bovespa;
using namespace B2bits::MD;
struct PerInstrumentListener : public InstrumentListener
{
void onSubscribed(BovespaSubscriptionItem const& item)
{
// instrument subscribed,
}
virtual void onUnsubscribed(BovespaSubscriptionItem const& subsItem)
{
// delete this
this->release();
}
virtual bool onSecurityDefinition(BovespaSubscriptionItem const& subsItem, FIXMessage const& dMsg) override
{
// process security definition message, 35=d
}
virtual bool onIncrement(BovespaSubscriptionItem const& subsItem, FIXMessage const* const* msgs, size_t count) {
// process incremental message, 35=X
}
virtual bool onNaturalRefresh(BovespaSubscriptionItem const& subsItem,
FIXMessage const* const* nrMsgs,
size_t count,
bool isNewSequence) override
{
// if NaturalRefresh is enabled updates will be available here, 35=X
}
virtual void onSnapshot(BovespaSubscriptionItem const& subsItem, FIXMessage const* msg) override {
// process snapshot message, 35=W
}
virtual void process(BovespaSubscriptionItem const& subsItem, FIXMessage const* msg) override {
// process other 35!=X, 35!=W
}
virtual void onRecoveryStarted(BovespaSubscriptionItem const& subsItem) override {
// mark instrument state as invalid
recovered_ = false;
}
virtual void onRecoveryStopped(BovespaSubscriptionItem const& subsItem, RecoveryReason reason) {
// mark instrument as valid
recovered_ = true;
}
virtual void onError(BovespaSubscriptionItem const& subsItem, Engine::AsciiString const& error) {
// log error
std::cerr << error << std::endl;
}
virtual void onBookReset(BovespaSubscriptionItem const& subsItem) override {
// reset instrument book
}
bool recovered_ = true;
};
class BovespaClient
{
public:
BovespaClient()
{
// Initialize parameters
// XML configs
params.templatesFn_ = "templates.xml";
params.configXml_ = "config.xml";
// TCP Replay parameters
params.tcpReplayParams_.senderCompId_ = "Sender";
params.tcpReplayParams_.targetCompId_ = "Target";
params.tcpReplayParams_.username_ = "username";
params.tcpReplayParams_.password_ = "12345";
params.tcpReplayParams_.ip_ = "1.2.3.4;";
params.tcpReplayParams_.port_ = 3001;
// Create Application object
app_ = Engine::FixEngine::singleton()->createBovespaApplication(params);
}
void subscribe(std::string const& symbol)
{
item.symbol_ = symbol;
item.recovery_ = RO_USE_MARKET_TCP_AS_POSIBLE_RECOVERY;
app_->subscribeToInstrument(item, new PerInstrumentListener());
}
void release() {
app_->release();
app_ = NULL;
}
private:
BovespaApplication* app_ = nullptr;
};
int main(int argc, char* argv[])
{
try
{
// Initialize engine.
Engine::init();
// Create Application instance
BovespaClient application;
// Subscribe for symbol
application.subscribe("EZTC3");
// Wait, receiving market data
char c;
std::cin >> c;
// release resources
application.release();
Engine::FixEngine::destroy();
}
catch (const std::exception& ex)
{
std::cout << " ERROR: " << ex.what() << std::endl;
return -1;
}
return 0;
}