• Version 1.16.0
Show / Hide Table of Contents

Session Events

The Session class exposes the following events:

Event Description
BytesReceived Data is received from the network.
Error Error condition is detected.
InboundApplicationMessage Application-level message is received from the counterparty.
InboundSessionMessage Session-level message is received from the counterparty.
MessageResending Sent application-level message is about to be resent to the counterparty. See Resending Messages.
ResendingStarted ResendRequest message is received and the session is about to start resending messages. See Resending Messages.
ResendingFinished Resending process is completed. See Resending Messages.
MessageSending Message will be sent to the counterparty. This event is raised just before the message is sent to the network.
OutboundApplicationMessage Application-level message will be sent to the counterparty. This event could be used to change the fields that are set by the FIX Engine.
OutboundSessionMessage Session-level message will be sent to the counterparty. This event could be used to change the fields that are set by the FIX Engine.
StateChanged Session state is changed.
Warning Warning condition is detected.
Note

Session event handling is a synchronous operation. Avoid performing time-consuming tasks inside event handlers.

Note

Session methods that change the Session's state (e.g., Logout(bool) ) should not be called from event handlers directly.

For example:

session.BytesReceived += (ReadOnlySpan<byte> args) =>
{
    Console.WriteLine($"Data is received from the network: {args.ToString()}");
};

session.Error += (object sender, SessionErrorEventArgs e) =>
{
    Console.WriteLine($"Error condition is detected: {e}");
};

session.InboundApplicationMessage += (object sender, InboundMessageEventArgs e) =>
{
    Console.WriteLine($"Application-level message is received from the counterparty: {e}");
};

session.InboundSessionMessage += (object sender, InboundMessageEventArgs e) =>
{
    Console.WriteLine($"Session-level message is received from the counterparty: {e}");
};

session.MessageResending += (object sender, MessageResendingEventArgs e) =>
{
    Console.WriteLine($"Sent application-level message is about to be resent to the counterparty: {e}");

    e.AllowResending = false;
};

session.MessageResending += (object sender, MessageResendingEventArgs e) =>
{
    Console.WriteLine($"Sent application-level message is about to be resent to the counterparty: {e}");

    e.AllowResending = false;
};

session.ResendingStarted += (object sender, ResendingStartedFinishedEventArgs e) =>
{
    Console.WriteLine($"ResendRequest (MsgType=2) message is received and the session is about to start resending messages: {e}");
};

session.ResendingFinished += (object sender, ResendingStartedFinishedEventArgs e) =>
{
    Console.WriteLine($"Resending process is completed: {e}");
};

session.OutboundApplicationMessage += (object sender, MessageEventArgs e) =>
{
    Console.WriteLine($"$Application-level message will be sent to the counterparty: {e}");
};

session.OutboundSessionMessage += (object sender, MessageEventArgs e) =>
{
    Console.WriteLine($"Session message will be sent to the counterparty: {e}");
};

session.StateChanged += (object sender, SessionStateChangeEventArgs e) =>
{
    Console.WriteLine($"Session state is changed: {e}");
};

session.Warning += (object sender, SessionWarningEventArgs e) =>
{
    Console.WriteLine($"Warning condition is detected: {e}");
};

Modifying Outgoing Messages

To modify outgoing messages use the following approach:

session.OutboundSessionMessage += (object sender, MessageEventArgs e) =>
{
    e.Message[Tag.Password] = "Cool password";
};

session.OutboundApplicationMessage += (object sender, MessageEventArgs e) =>
{
    e.Message[Tag.ClOrdID] = "ClOrdID 2";
};
In this article
Back to top Copyright © Onix Solutions.
Generated by DocFX