UMDF Quck Start
These chapters describe the creation of a simple Bovespa application step-by step with samples.
Follow these instructions to get it to work:
- Initialize FIX engine
- Create BovespaApplication
- Subscribe to symbol
- Process incoming market data
- Stop, release resources
Engine initialization
Execute the following instruction to initialize FIX engine.
// 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.
// 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.
// Initializes engine. try { Engine::FixEngine::init("engine.properties"); } catch( const Utils::Exception& ex ) { cout << "ERROR: " << ex.what() << endl; }
BovespaApplication creation
You can create an BovespaApplication in three steps:
- Configure BovespaApplication parameters
- Create an 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::subscribe method for that. Market data will be delivered to the listener's callbacks
auto listener = new PerInstrumentListener(); BovespaSubscriptionItem item; item.symbol_ = symbol; app_->subscribeToInstrument(item, listener);
Releasing resources
Use the BovespaApplication::release() method to release the resources. Calling unsubscribe is optional.
Full sample
The sample below illustrates all above mentioned instructions combined in one application.
#include <iostream> #include <string> #include <B2BITS_FixEngine.h> #include <B2BITS_BovespaApplication.h> #include <B2BITS_BovespaApplicationListeners.h> using namespace Bovespa; 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, Engine::FIXMessage const& dMsg) override { // process security definition message, 35=d } virtual bool onIncrement(BovespaSubscriptionItem const& subsItem, Engine::FIXMessage const* const* msgs, size_t count) { // process incremental message, 35=X } virtual bool onNaturalRefresh(BovespaSubscriptionItem const& subsItem, Engine::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, Engine::FIXMessage const* msg) override { // process snapshot message, 35=W } virtual void process(BovespaSubscriptionItem const& subsItem, Engine::FIXMessage const* msg) override { // process other 35!=X, 35!=W } virtual void onRecoveryStarted(BovespaSubscriptionItem const& subsItem) override { // mark instrument 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 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); } void subscribe(std::string const& symbol) { auto listener = new PerInstrumentListener(); BovespaSubscriptionItem item; item.symbol_ = symbol; item.recovery_ = RO_USE_MARKET_TCP_AS_POSIBLE_RECOVERY; app_->subscribeToInstrument(item, listener); } void release() { app_->release(); app_ = NULL; } private: BovespaApplication* app_ = nullptr; }; int main(int argc, char* argv[]) { try { // Initialize engine. Engine::FixEngine::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 Utils::Exception& ex) { std::cout << " ERROR: " << ex.what() << std::endl; return -1; } return 0; }