OnixS C++ ICE Binary Order Entry Handler 1.0.0
API Documentation
Loading...
Searching...
No Matches
Thread Pool Mode Sample

This sample demonstrates how to use the ThreadPool threading model.

Source code

#include "../Settings/Defaults.h"
#include "../Common/Helpers.h"
#include "../Common/Listener.h"
#include "../Common/Settings.h"
#include "../Common/Signal.h"
#include "../Common/Emulator.h"
using namespace Samples;
int main(int argc, char * argv[])
{
// `--help` to show options
const AppConfiguration<
SettingsConfiguration, ConnectivityConfiguration, LogonConfiguration, StorageConfiguration<SessionStorageType::FileBased>
> cfg{"ThreadPoolMode", argc, argv};
try
{
SignalHelper::manageSignals();
auto settings = fillSettings(cfg);
const auto emulator = createEmulator(settings, cfg);
// Request Binary Order Gateway credentials from Binary Utility Service Gateway
const auto bgwCredentials = receiveBgwCredentials(settings, cfg.host(), cfg.port());
settings.threadingModel(ThreadingModel::Pool);
settings.ipSessionToken(bgwCredentials.ipSessionToken);
Listener listener;
const auto bgwSession= createSession(SessionType::BGW, settings, &listener, cfg.storage());
bgwSession->connect(bgwCredentials.host, bgwCredentials.port);
bgwSession->send(Helper::createTraderLogonRequest(cfg.traderId(), cfg.traderPwd()));
Samples::wait(listener.traderLoggedOn).get();
bgwSession->send(Helper::createOrder(cfg.traderId()));
SignalHelper::waitUntilKey("disconnect the BGW session and terminate the application");
bgwSession->send(Helper::createTraderLogoutRequest(cfg.traderId())).disconnect();
}
catch(const std::exception & ex)
{
std::cerr << "\nEXCEPTION: " << ex.what() << std::endl;
return 1;
}
return 0;
}