OnixS C++ ICE Binary Order Entry Handler 1.0.0
API Documentation
Loading...
Searching...
No Matches
Getting Started Sample

This sample shows how to connect to the BUS Gateway and BGW or the local Gateway emulator.

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"
#include "../Common/BenchmarkData.h"
#include "../Common/PerformanceCounter.h"
#include "../Common/BenchmarkGatewayListener.h"
#include "../Common/BenchmarkSessionListener.h"
using namespace Samples;
int main(int argc, char * argv[])
{
// `--help` to show options
const AppConfiguration<
SettingsConfiguration
, ConnectivityConfiguration
, LogonConfiguration
, StorageConfiguration<SessionStorageType::FileBased>
> cfg{"GettingStarted", argc, argv};
try
{
SignalHelper::manageSignals();
auto settings = fillSettings(cfg);
const auto emulator = createEmulator(settings, cfg);
// A `SessionListener` instance
Listener listener;
// Credentials for Binary Order Gateway service
Tools::BgwCredentials bgwCredentials;
// Request Binary Order Gateway credentials from Binary Utility Service Gateway
{
// Create an instance of a `BUS` session
const auto busSession= createSession(SessionType::BUS, settings, &listener, cfg.storage());
// Connect and send `IPRequest` message
busSession->connect(cfg.host(), cfg.port()).send(Helper::createIpRequest(cfg.clientId(), cfg.userId()));
// Wait until `IPReport` is received
auto future = Samples::wait(listener.ipReportReceivedEvent);
busSession->disconnect();
// Save Binary Order Gateway service credentials
bgwCredentials = future.get();
}
// Log in and put an order to Binary Order Gateway service
{
// Set the access key assigned by the exchange
settings.ipSessionToken(bgwCredentials.ipSessionToken);
// Create an instance of a `BGW` session
const auto bgwSession= createSession(SessionType::BGW, settings, &listener, cfg.storage());
// Connect and send `TraderLogonRequest` message
bgwSession->connect(bgwCredentials.host, bgwCredentials.port);
bgwSession->send(Helper::createTraderLogonRequest(cfg.traderId(), cfg.traderPwd()));
// Wait until `TraderLogonReport` is received
Samples::wait(listener.traderLoggedOn).get();
// Put an order
bgwSession->send(Helper::createOrder(cfg.traderId()));
SignalHelper::waitUntilKey("disconnect the BGW session and terminate the application");
// Log out and disconnect
bgwSession->send(Helper::createTraderLogoutRequest(cfg.traderId())).disconnect();
}
}
catch(const std::exception & ex)
{
std::cerr << "\nEXCEPTION: " << ex.what() << std::endl;
return 1;
}
return 0;
}