This sample connects to the pre-defined host and port (acts as a FIX Initiator). When the session is established, the SingleOrder - New
FIX message is sent to the counterparty. This is done using the ExternalThread threading model.
#include "Listener.h"
#include <iostream>
#include <string>
{
std::clog << "\nIncoming application-level message:\n" << msg << std::endl;
}
{
std::clog << "\nIncoming session-level message:\n" << msg << std::endl;
}
{
std::clog
<< "\nSession's state is changed, prevState="
<< ", newState="
<< std::endl;
finished_ = true;
}
{
std::cerr << "\nSession-level error:" << description << std::endl;
finished_ = true;
}
{
std::cerr << "\nSession-level warning:" << description << std::endl;
}
#include "Listener.h"
#include "../../Common/Helpers.h"
#include "../../Common/Settings.h"
using namespace Settings;
int main()
{
std::clog << "ExternalThread sample." << std::endl << std::endl;
try
{
manageLinuxSignals();
Engine::init(settings, &stack);
Listener acceptorListener;
Session acceptor(&stack, TargetCompId, SenderCompId, FixProtocolVersion, &acceptorListener);
acceptor.logonAsAcceptor();
Listener initiatorListener;
Session initiator(&stack, SenderCompId, TargetCompId, FixProtocolVersion, &initiatorListener);
const bool SetResetSeqNumFlagOnLogon = true;
const int HeartBtInt = 30;
{
while(!logonTask.
isReady() && !timer.elapsed())
if(timer.elapsed())
{
std::clog << std::endl << "Cannot logon during the timeout." << std::endl;
initiator.breakConnection();
}
{
try
{
}
catch(const std::exception & ex)
{
std::clog << std::endl << "Logon fails with error: " << ex.what() << std::endl;
}
}
}
std::clog << "Press any key to send an order, disconnect the session and terminate the application." << std::endl;
while(!acceptorListener.finished() && !initiatorListener.finished() && !keyPressed())
Message order(
"D", FixProtocolVersion);
setOrderFields(&order);
initiator.send(&order);
{
while((!logoutTask.
isReady() || !initiatorListener.finished()) && !timer.elapsed())
if(timer.elapsed())
{
std::clog << std::endl << "Cannot logout during the timeout." << std::endl;
initiator.breakConnection();
}
{
try
{
}
catch(const std::exception & ex)
{
std::clog << std::endl << "Logout fails with error: " << ex.what() << std::endl;
}
}
}
initiator.shutdown();
acceptor.shutdown();
Engine::shutdown();
}
catch(const std::exception & ex)
{
processSampleException(ex.what());
return 1;
}
return 0;
}