#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[])
{
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);
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;
}