OnixS C++ FIX Engine  3.24.0
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:
virtual void onInboundApplicationMsg(const Message& message, Session*)
{
// Processing incoming application-level message..
std::clog
<< "Incoming application-level message: "
<< message.toString()
<< std::endl;
}
};
...
const string SENDER_COMP_ID = "AcceptorAndInitiator_SND";
const string TARGET_COMP_ID = "AcceptorAndInitiator_TRG";
const string ACCEPTOR_HOST = "localhost";
int ACCEPTOR_PORT = Engine::instance()->listenPort();
SessionListener listener;
Session acceptor(SENDER_COMP_ID, TARGET_COMP_ID, VERSION, &listener);
Session initiator(TARGET_COMP_ID, SENDER_COMP_ID, VERSION, &listener);
acceptor.logonAsAcceptor();
initiator.logonAsInitiator(ACCEPTOR_HOST, ACCEPTOR_PORT);
Message order(Values::MsgType::OrderSingle, VERSION);
order.set(Tags::ClOrdID, "20080808-0955789");
order.set(Tags::HandlInst, Values::HandlInst::AutomatedExecutionOrderPrivateNoBrokerIntervention);
order.set(Tags::Symbol, "MSFT");
order.set(Tags::OrderQty, 100000);
order.set(Tags::Side, Values::Side::Buy);
order.set(Tags::OrdType, Values::OrdType::Market);
order.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();