This sample connects to the configured host and port (acts as a FIX Initiator). When the session is established, the SingleOrder - New FIX message is sent to the counterparty.
{
public:
Listener();
OnixS::Threading::Semaphore & completionEvent();
bool failed() const;
void onInboundApplicationMsg(OnixS::FIX::Message & msg, OnixS::FIX::Session * sn) final;
void onInboundSessionMsg(OnixS::FIX::Message & msg, OnixS::FIX::Session * sn) final;
private:
void recordFailure();
OnixS::Threading::Semaphore executionReportReceived_;
mutable OnixS::Threading::Mutex failureMutex_;
bool failed_;
};
#include "Listener.h"
#include <OnixS/FIXEngine/FIX/FIX44.h>
#include <iostream>
#include <string>
Listener::Listener() : executionReportReceived_(0), failed_(false) {}
{
return executionReportReceived_;
}
bool Listener::failed() const
{
return failed_;
}
void Listener::recordFailure()
{
failed_ = true;
}
{
std::clog << "\nIncoming application-level message:\n" << msg << std::endl;
if(msg.
type() != FIX44::Values::MsgType::ExecutionReport)
return;
std::clog << "Received ExecutionReport." << std::endl;
executionReportReceived_.release();
}
{
std::clog << "\nIncoming session-level message:\n" << msg << std::endl;
if(msg.
type() == FIX44::Values::MsgType::Logon)
std::clog << "BuySide received Logon." << std::endl;
}
{
std::clog
<< "\nSession's state is changed, prevState="
<< ", newState="
<< std::endl;
}
{
recordFailure();
executionReportReceived_.release();
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/SampleArguments.h"
#include "../../Common/Settings.h"
using namespace OnixS::FIX::FIX44;
using namespace Settings;
int runBuySide(const Sample::Arguments & arguments)
{
std::clog << "BuySide sample." << std::endl << std::endl;
try {
manageLinuxSignals();
EngineShutdownGuard engineShutdownGuard;
Listener listener;
Session session(SenderCompId, TargetCompId, FixProtocolVersion, &listener);
Message customLogon(Values::MsgType::Logon, FixProtocolVersion);
bool setResetSeqNumFlagInLogon = true;
customLogon.setFlag(Tags::ResetSeqNumFlag, setResetSeqNumFlagInLogon);
const std::string rawData;
if(! rawData.empty()) {
customLogon.set(Tags::RawData, rawData)
.set(Tags::RawDataLength, (int) rawData.size());
}
const std::string counterpartyHost = "localhost";
const int heartBtInt = 30;
#ifdef SSL_ENCRYPTION
std::clog << "SSL Mode." << std::endl;
#endif
session.logonAsInitiator(counterpartyHost, arguments.port, heartBtInt, &customLogon);
Sample::waitForUser(arguments, "Press any key to send the order...");
Message order(Values::MsgType::NewOrderSingle, FixProtocolVersion);
setOrderFields(&order);
session.send(&order);
std::clog << "The order " << std::endl << order << std::endl << " was sent" << std::endl;
Sample::waitForUserOrEvent(
arguments,
"Press any key to disconnect the session and terminate the application.",
listener.completionEvent());
session.logout("The session is disconnected by BuySide").shutdown();
if(listener.failed())
return 1;
std::clog << "BuySide completed successfully." << std::endl;
}
catch(const std::exception & ex) {
processSampleException(ex.what());
return 1;
}
return 0;
}
int main(int argc, char * argv[])
{
const int defaultPort =
#ifdef SSL_ENCRYPTION
SslListenPort;
#else
ListenPort;
#endif
return Sample::runSample(argc, argv, defaultPort, &runBuySide);
}