OnixS C++ FIX Engine  4.10.1
API Documentation
Exchanging Messages

Sending Messages to a Counterparty

To send a message to a counterparty, the OnixS::FIX::Session::send method must be used. This method is asynchronous. As soon as a session is created, it is possible to start sending messages via the session. If the session is not established, the messages are stored in the session storage and will be sent in replay to the resend request when the connection is established with the counterparty and the sequence numbers mismatch is detected (please see the Resending Messages page).

Receiving Messages from Counterparty

To receive incoming application-level messages, it is necessary to override the OnixS::FIX::ISessionListener::onInboundApplicationMsg method of OnixS::FIX::ISessionListener Class and pass instance of the descendant class to the OnixS::FIX::Session's constructor.

Example

using namespace OnixS::FIX;
using namespace OnixS::FIX::FIX42;
class SessionListener : public ISessionListener
{
public:
void onInboundApplicationMsg(Message & message, Session *) ONIXS_FIXENGINE_OVERRIDE
{
// Processing incoming application-level message..
std::clog
<< "Incoming application-level message: "
<< message.toString()
<< std::endl;
}
};
const std::string SenderCompId = "AcceptorAndInitiator_SND";
const std::string TargetCompId = "AcceptorAndInitiator_TRG";
const std::string AcceptoHost = "localhost";
const int AcceptorPort = Engine::instance()->listenPort();
SessionListener listener;
Session acceptor(SenderCompId, TargetCompId, version, &listener);
Session initiator(TargetCompId, SenderCompId, version, &listener);
acceptor.logonAsAcceptor();
initiator.logonAsInitiator(AcceptoHost, AcceptorPort);
Message order(Values::MsgType::Order_Single, version);
order.set(Tags::ClOrdID, "20080808-0955789")
.set(Tags::HandlInst, Values::HandlInst::Automated_execution_order_private_no_Broker_intervention)
.set(Tags::Symbol, "MSFT")
.set(Tags::OrderQty, 100000)
.set(Tags::Side, Values::Side::Buy)
.set(Tags::OrdType, Values::OrdType::Market)
.set(Tags::TransactTime, "20051012-22:10:11");
order.validate();
initiator.send(&order);
// Continues the message exchange..
// Done with messaging.
initiator.logout();
acceptor.logout();
initiator.shutdown();
acceptor.shutdown();