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.
Source code:
- Listener.h
- Listener.cpp
- SellSide.cpp
Listener.h:
{
public:
Listener();
private:
int ordersCounter_;
};
Listener.cpp:
#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")
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::cerr << "\nSession-level error:" << description << std::endl;
}
{
std::cerr << "\nSession-level warning:" << description << std::endl;
}
SellSide.cpp:
#include "Listener.h"
#include "../../Common/Helpers.h"
#include "../../Common/Settings.h"
using namespace Settings;
namespace {
{
public:
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
MyEngineListener engineListener;
Listener listener;
Session session(TargetCompId, SenderCompId, FixProtocolVersion, &listener);
#ifdef SSL_ENCRYPTION
#endif
session.logonAsAcceptor();
std::clog <<
"Awaiting session-initiator on port " << settings.
listenPort() <<
"..." << std::endl;
getchar();
session.logout().shutdown();
}
catch(const std::exception & ex) {
processSampleException(ex.what());
return 1;
}
return 0;
}