#include "../Common/Helpers.h"
#include "../Common/Listener.h"
int main(int argc, char * argv[])
{
clog << "CME iLink 3 ExternalThreadMode Sample." << endl << endl;
int marketSegmentId = 99;
string host = "127.0.0.1";
bool useEmulator = false;
if (argc < 4)
{
#if defined(ONIXS_ILINK3_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 int securityId = argc > 4 ? atoi(argv[4]) : DefaultSecurityId;
const Int64 priceMantissa = argc > 5 ? fromStr<Int64>(argv[5]) : DefaultPriceMantissa;
try
{
SignalHelper::manageLinuxSignals();
SessionSettings settings = fillSettings(useEmulator);
#if defined(ONIXS_ILINK3_HAS_GATEWAY_EMULATOR)
std::unique_ptr<GatewayEmulatorThread> gateway;
if (useEmulator)
gateway.reset(new GatewayEmulatorThread(settings.licenseStores(), host, port));
#endif
settings.threadingModel(ThreadingModel::External);
NewOrderSingle order;
Helper::setOrderFields(order, PartyDetailsListReqID, securityId, priceMantissa);
TcpStandardStack stack;
Listener listener;
Session session(stack, settings, marketSegmentId, &listener);
Threading::SharedFuture<void> connectTask = session.
connectAsync(host, port);
while(!connectTask.is_ready())
stack.dispatchEvents();
clog << "\nThe order was sent." << endl;
clog << "\nPress any key to disconnect the session and terminate the application." << endl;
while(!Helper::keyPressed())
stack.dispatchEvents();
Threading::SharedFuture<void> disconnectTask = session.
disconnectAsync(
"The session is disconnected");
while(!disconnectTask.is_ready() || !stack.isQuiescent())
stack.dispatchEvents();
}
catch(const std::exception & ex)
{
cerr << "\nEXCEPTION: " << ex.what() << endl;
return 1;
}
return 0;
}