OnixS C++ B3 BOE Binary Order Entry  1.2.0
API Documentation
Thread Pool Mode Sample

This sample demonstrates how to use the ThreadPool threading model.

Source code

#include "../Common/Helpers.h"
#include "../Common/Listener.h"
int main(int argc, char * argv[])
{
clog << "B3 BOE ThreadPoolMode Sample." << endl << endl;
MarketSegmentID marketSegmentId = DefaultMarketSegmentId;
string host = "127.0.0.1";
Port port = 49152;
bool useEmulator = false;
if (argc < 4)
{
#if defined(ONIXS_B3_BOE_HAS_GATEWAY_EMULATOR)
useEmulator = true;
#else
std::cerr << "usage: [MarketSegmentId] [Host] [Port] (SecurityId) (PriceMantissa)" << std::endl;
return 1;
#endif
}
else
{
marketSegmentId = atoi(argv[1]);
host = argv[2];
port = atoi(argv[3]);
}
const SecurityID securityId = argc > 4 ? static_cast<SecurityID>(atoi(argv[4])) : DefaultSecurityId;
const Int64 priceMantissa = argc > 5 ? fromStr<Int64>(argv[5]) : DefaultPriceMantissa;
try
{
SignalHelper::manageLinuxSignals();
SessionSettings settings = fillSettings(useEmulator);
#if defined(ONIXS_B3_BOE_HAS_GATEWAY_EMULATOR)
std::unique_ptr<GatewayEmulatorThread> gateway;
if (useEmulator)
gateway.reset(new GatewayEmulatorThread(settings.licenseStores(), host, port));
#endif
settings.threadingModel(ThreadingModel::Pool);
NewOrderSingle order;
Helper::setOrderFields(order, marketSegmentId, securityId, DefaultAccount, priceMantissa);
Listener listener;
Session session(settings, &listener);
session
.connect(host, port)
.send(order);
clog << "\nThe order was sent." << endl;
Helper::waitUntilEnterKey("disconnect the session and terminate the application");
session.disconnect();
}
catch(const std::exception & ex)
{
cerr << "\nEXCEPTION: " << ex.what() << endl;
return 1;
}
return 0;
}