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.
#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;
}
{
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 OnixS::FIX::FIX44;
using namespace Settings;
int main()
{
std::clog << "BuySide sample." << std::endl << std::endl;
try {
manageLinuxSignals();
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 counterpartyPort =
#ifdef SSL_ENCRYPTION
SslListenPort;
#else
ListenPort;
#endif
const int heartBtInt = 30;
#ifdef SSL_ENCRYPTION
std::clog << "SSL Mode." << std::endl;
#endif
session.
logonAsInitiator(counterpartyHost, counterpartyPort, heartBtInt, &customLogon);
std::clog << "Press any key to send the order..." << std::endl;
waitUntilEnterKey();
Message order(Values::MsgType::NewOrderSingle, FixProtocolVersion);
setOrderFields(&order);
std::clog << "The order " << std::endl << order << std::endl << " was sent" << std::endl;
std::clog << "Press any key to disconnect the session and terminate the application." << std::endl;
waitUntilEnterKey();
}
catch(const std::exception & ex) {
processSampleException(ex.what());
return 1;
}
return 0;
}