OnixS C++ FIX Engine  4.10.1
API Documentation

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.


Source code:


Listener.h:

class Listener : public OnixS::FIX::ISessionListener
{
public:
/// Is called when the application-level message is received from the counterparty.
void onInboundApplicationMsg(Message & msg, Session * sn) ONIXS_FIXENGINE_FINAL;
/// Is called when the session-level message is received from the counterparty.
void onInboundSessionMsg(Message & msg, Session * sn) ONIXS_FIXENGINE_FINAL;
void onStateChange(SessionState::Enum newState, SessionState::Enum prevState, Session * sn) ONIXS_FIXENGINE_FINAL;
void onError(ErrorReason::Enum reason, const std::string & description, Session * sn) ONIXS_FIXENGINE_FINAL;
void onWarning(WarningReason::Enum reason, const std::string & description, Session * sn) ONIXS_FIXENGINE_FINAL;
};

Listener.cpp:

#include "Listener.h"
void Listener::onInboundApplicationMsg(Message & msg, Session * /*sn*/)
{
std::clog << "\nIncoming application-level message:\n" << msg << std::endl;
}
void Listener::onInboundSessionMsg(Message & msg, Session * /*sn*/)
{
std::clog << "\nIncoming session-level message:\n" << msg << std::endl;
}
void Listener::onStateChange(SessionState::Enum newState, SessionState::Enum prevState,
Session * /*sn*/)
{
std::clog
<< "\nSession's state is changed, prevState="
<< SessionState::toString(prevState)
<< ", newState="
<< SessionState::toString(newState)
<< std::endl;
}
void Listener::onError(ErrorReason::Enum /*reason*/, const std::string & description, Session * /*sn*/)
{
std::cerr << "\nSession-level error:" << description << std::endl;
}
void Listener::onWarning(WarningReason::Enum /*reason*/, const std::string & description,
Session * /*sn*/)
{
std::cerr << "\nSession-level warning:" << description << std::endl;
}

BuySide.cpp:

#include "Listener.h"
#include "../../Common/Helpers.h"
#include "../../Common/Settings.h"
using namespace Settings;
// Uncomment if you'd like to test SSL feature.
//#define SSL_ENCRYPTION 1
int main()
{
std::clog << "BuySide sample." << std::endl << std::endl;
try {
manageLinuxSignals();
EngineSettings settings;
settings.dictionaryFile("FixDialectDescription.xml")
.licenseStore(LicenseStore);
Engine::init(settings);
Listener listener;
Session session(SenderCompId, TargetCompId, FixProtocolVersion, &listener);
Message customLogon(MsgType::Logon, FixProtocolVersion);
bool setResetSeqNumFlagInLogon = true; // For testing only!
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;
// Uncomment the line below if you would like to set the outgoing message sequence number "manually".
//session.setOutSeqNum(11);
#ifdef SSL_ENCRYPTION
std::clog << "SSL Mode." << std::endl;
session.encryptionMethod(EncryptionMethod::SSL);
#endif
session.logonAsInitiator(counterpartyHost, counterpartyPort, heartBtInt, &customLogon);
std::clog << "Press any key to send the order..." << std::endl;
waitUntilEnterKey();
Message order(MsgType::Order_Single, FixProtocolVersion);
setOrderFields(&order);
session.send(&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();
session.logout("The session is disconnected by BuySide").shutdown();
Engine::shutdown();
}
catch(const std::exception & ex) {
processSampleException(ex.what());
return 1;
}
return 0;
}