This sample waits for incoming connections on the pre-defined port (acts as a FIX Acceptor). If the incoming application-level message is SingleOrder - New
then the ExecutionReport
message is send to the counterparty. Otherwise the Email
message is sent back.
#include "Listener.h"
#include <OnixS/FIXEngine/FIX/FIX44.h>
#include "../../Common/Settings.h"
#include "../../Common/Helpers.h"
using namespace Settings;
using namespace OnixS::FIX::FIX44;
using namespace OnixS::FIX::FIX44::Values;
Listener::Listener() : ordersCounter_(0) {}
{
std::clog << "\nIncoming application-level message:\n" << msg << std::endl;
try {
if(msg.
type() == MsgType::NewOrderSingle) {
Message * execReport =
new Message(MsgType::ExecutionReport, FixProtocolVersion);
const int EXEC_ID_SIZE = 128;
char execID[EXEC_ID_SIZE];
xsnprintf(execID, EXEC_ID_SIZE - 1, "ExecID_%d", ++ordersCounter_);
execReport->
set(Tags::ExecID, execID)
.
set(Tags::ExecType,
"0")
.
set(Tags::ExecTransType,
"0")
.
set(Tags::OrdStatus,
"0")
.
set(Tags::OrderQty, order.
get(Tags::OrderQty).
toString())
.
set(Tags::CumQty, order.
get(Tags::OrderQty).
toString())
.set(Tags::AvgPx, 100.0)
reply = execReport;
}
else {
email->
set(Tags::EmailType, 0);
group[0].set(Tags::Text,
"The message with MsgType=" + msg.
type().
toString() +
" was received");
reply = email;
}
std::clog << "\nSent to the counterparty:\n" << *reply << std::endl;
}
delete reply;
}
catch(const std::exception & ex) {
std::clog << "Exception during the processing of incoming message: " << ex.what() << std::endl;
}
}
{
std::clog << "\nIncoming session-level message:\n" << msg << std::endl;
}
{
std::clog << "\nSession's state is changed, prevState=" << SessionState::toString(prevState)
<< ", newState=" << SessionState::toString(newState) << std::endl;
}
{
std::cerr << "\nSession-level error:" << description << std::endl;
}
{
std::cerr << "\nSession-level warning:" << description << std::endl;
}
#include "Listener.h"
#include "../../Common/Helpers.h"
#include "../../Common/Settings.h"
using namespace Settings;
namespace {
{
public:
void onUnknownIncomingConnection(
const FlatMessage & ,
const int ,
const int , const std::string & ,
std::cerr << "\nEngine-level error: " << description << std::endl;
}
std::cerr << "\nEngine-level warning: " << description << std::endl;
}
};
}
int main()
{
std::clog << "SellSide sample." << std::endl << std::endl;
try {
manageLinuxSignals();
#ifdef SSL_ENCRYPTION
std::clog << "SSL Mode." << std::endl;
#else
#endif
Engine::init(settings);
MyEngineListener engineListener;
Engine::instance()->registerListener(&engineListener);
Listener listener;
Session session(TargetCompId, SenderCompId, FixProtocolVersion, &listener);
#ifdef SSL_ENCRYPTION
#endif
std::clog <<
"Awaiting session-initiator on port " << settings.
listenPort() <<
"..." << std::endl;
getchar();
Engine::shutdown();
}
catch(const std::exception & ex) {
processSampleException(ex.what());
return 1;
}
return 0;
}