#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[])
{
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);
Listener listener;
Tools::BgwCredentials bgwCredentials;
{
const auto busSession= createSession(SessionType::BUS, settings, &listener, cfg.storage());
busSession->connect(cfg.host(), cfg.port()).send(Helper::createIpRequest(cfg.clientId(), cfg.userId()));
auto future = Samples::wait(listener.ipReportReceivedEvent);
busSession->disconnect();
bgwCredentials = future.get();
}
{
settings.ipSessionToken(bgwCredentials.ipSessionToken);
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;
}