Class Session
A FIXP Session to Market Segment Gateway (MSGW). It is defined as a bi-directional stream of ordered messages between two parties within a continuous sequence number series. A single FIXP session can exist across multiple sequential (not concurrent) physical connections. A FIX Connection is comprised of three parts: logon, message exchange, and logout. A FIX Session is comprised of one or more FIX Connections, meaning that a FIX Session spans multiple logins. Parties can connect and disconnect multiple times while maintaining a single FIXP session. Connecting parties must bi-laterally agree as to when sessions are to be started/stopped based upon individual system and time zone requirements. Resetting the inbound and outbound sequence numbers back to 1, for whatever reason, constitutes the beginning of a new FIXP session.
Implements
Inherited Members
Namespace: OnixS.Cme.ILink3
Assembly: OnixS.Cme.ILink3.dll
Syntax
public class Session : IDisposable
Constructors
Session(SessionSettings, int, SessionStorageType, ulong, string, LogFactory)
Creates a Market Segment Gateway session.
Declaration
public Session(SessionSettings settings, int marketSegmentId, SessionStorageType storageType = SessionStorageType.FileBasedStorage, ulong uuid = 0, string customKey = "", LogFactory factory = null)
Parameters
| Type | Name | Description |
|---|---|---|
| SessionSettings | settings | Session settings |
| int | marketSegmentId | Market Segment ID |
| SessionStorageType | storageType | |
| ulong | uuid | |
| string | customKey | |
| LogFactory | factory |
Session(SessionSettings, int, ISessionStorage, LogFactory)
Creates a Market Segment Gateway session.
Declaration
public Session(SessionSettings settings, int marketSegmentId, ISessionStorage sessionStorage, LogFactory factory = null)
Parameters
| Type | Name | Description |
|---|---|---|
| SessionSettings | settings | |
| int | marketSegmentId | |
| ISessionStorage | sessionStorage | Custom session storage implementation |
| LogFactory | factory |
Session(ThreadManager, SessionSettings, int, SessionStorageType, ulong, string, LogFactory)
Creates a Market Segment Gateway session.
Declaration
public Session(ThreadManager threadManager, SessionSettings settings, int marketSegmentId, SessionStorageType storageType = SessionStorageType.FileBasedStorage, ulong uuid = 0, string customKey = "", LogFactory factory = null)
Parameters
| Type | Name | Description |
|---|---|---|
| ThreadManager | threadManager | |
| SessionSettings | settings | Session settings |
| int | marketSegmentId | Market Segment ID |
| SessionStorageType | storageType | |
| ulong | uuid | |
| string | customKey | |
| LogFactory | factory |
Fields
UndefinedUuid
Declaration
public const ulong UndefinedUuid = 0
Field Value
| Type | Description |
|---|---|
| ulong |
Properties
AccessKey
Declaration
public string AccessKey { get; }
Property Value
| Type | Description |
|---|---|
| string |
BackupIpAddress
Declaration
public string BackupIpAddress { get; }
Property Value
| Type | Description |
|---|---|
| string |
CounterpartyHost
Counterparty host name.
Declaration
public string CounterpartyHost { get; }
Property Value
| Type | Description |
|---|---|
| string | Counterparty host name |
CounterpartyIpAddress
Counterparty IP address.
Declaration
public IPAddress CounterpartyIpAddress { get; }
Property Value
| Type | Description |
|---|---|
| IPAddress | Counterparty IP address |
CounterpartyPort
Counterparty port number.
Declaration
public int CounterpartyPort { get; }
Property Value
| Type | Description |
|---|---|
| int | Counterparty port |
CreationTime
The time when the session instance was created or the last local reset of sequence numbers was performed.
Declaration
public DateTime CreationTime { get; }
Property Value
| Type | Description |
|---|---|
| DateTime | Session's creation time |
FaultToleranceIndicator
Indicates whether the connection is the primary or backup.
Declaration
public FaultToleranceIndicator FaultToleranceIndicator { get; set; }
Property Value
| Type | Description |
|---|---|
| FaultToleranceIndicator |
InSeqNum
The expected sequence number of the next incoming application-level message.
Declaration
public int InSeqNum { get; set; }
Property Value
| Type | Description |
|---|---|
| int | The expected sequence number of the next incoming application-level message |
IncomingMessageGapQueueMaximumSize
Returns maximum size of the incoming message gap queue.
Declaration
public int IncomingMessageGapQueueMaximumSize { get; set; }
Property Value
| Type | Description |
|---|---|
| int | maximum size of the incoming message gap queue. |
IsDisposed
Gets a value indicating whether the Session has been disposed of.
Declaration
public bool IsDisposed { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
KeepAliveInterval
The longest time in milliseconds the client system can remain silent before sending a keep alive message.
Allowed range is between 5000-60000. Any value outside this range will be rejected.
If no message is sent from customer after 1 interval lapses, CME will send a Sequence message indicating that one keep alive interval from customer has lapsed. If still no response is sent from the customer and the second keep alive interval lapses, the session will be terminated.
Declaration
public int KeepAliveInterval { get; }
Property Value
| Type | Description |
|---|---|
| int |
LicenseExpirationDate
Returns the license expiration date.
Declaration
public DateTime LicenseExpirationDate { get; }
Property Value
| Type | Description |
|---|---|
| DateTime |
LocalNetworkInterface
The network interface for establishing the TCP connection as an Initiator. The default value is LocalNetworkInterface.
Declaration
public IPAddress LocalNetworkInterface { get; set; }
Property Value
| Type | Description |
|---|---|
| IPAddress | The network interface for establishing the TCP connection as an Initiator |
LocalPort
Returns the local port that is used by the outgoing connection.
Declaration
public int LocalPort { get; }
Property Value
| Type | Description |
|---|---|
| int | Local ports |
See Also
LocalPortRange
The local port range for outgoing connections, the first available port from this range will be used to send and receive data. By default, a random port will be used.
Declaration
public PortRange LocalPortRange { get; set; }
Property Value
| Type | Description |
|---|---|
| PortRange | Local port range. |
LocalTimeUsage
Use the local time in Handler events and log files. The default value is LocalTimeUsage. The property key is LocalTimeUsage.
Declaration
public bool LocalTimeUsage { get; }
Property Value
| Type | Description |
|---|---|
| bool |
LogBeforeSending
Option to switch on/off logging of outbound messages before/after sending. By default, the logging of an outgoing message to the session storage is performed before sending to the wire. This is more reliable because we guarantee that an outgoing message is stored before going to the counterparty and if the application is shut down after sending, for some reasons, the sent message can be resent afterward. However, this approach adds the logging latency to the Handler sending latency. As a result, it increases the tick-to-trade latency. When the latency is more important, one can switch off the logging before sending, by setting the OnixS::FIX::Session::logBeforeSending option to false. In this case, the logging of outgoing messages to the session storage will be performed after sending to the wire. This way, one can exclude the logging latency from the Handler sending latency and as a result, decrease the tick-to-trade latency.
Declaration
public bool LogBeforeSending { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
MessageGrouping
Message sending grouping. The default value is MessageGrouping.
Declaration
public int MessageGrouping { get; set; }
Property Value
| Type | Description |
|---|---|
| int | Value |
Negotiated
Declaration
public bool Negotiated { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
OutSeqNum
The sequence number of the next outgoing application-level message.
Declaration
public int OutSeqNum { get; set; }
Property Value
| Type | Description |
|---|---|
| int | The sequence number of the next outgoing application-level message |
PreviousSeqNo
The sequence number of the last business message published by CME with the PreviousUUID.
If no business message was published, the value is zero.
Declaration
public int PreviousSeqNo { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
PreviousUuid
The UUID sent in the previous message before this message from CME.
- This can be the CME assigned default UUID=0 for messages published by CME before first Negotiation of customer at the beginning of the week.
- This can be the last UUID as used by the customer from the previously Established session.
If no business message has been published by CME, this will also be set to 0.
Declaration
public ulong PreviousUuid { get; set; }
Property Value
| Type | Description |
|---|---|
| ulong |
PrimaryIpAddress
Declaration
public string PrimaryIpAddress { get; }
Property Value
| Type | Description |
|---|---|
| string |
ReasonableTransmissionTime
Reasonable transmission time as % from the heartbeat interval. The default value is ReasonableTransmissionTime.
Declaration
public int ReasonableTransmissionTime { get; set; }
Property Value
| Type | Description |
|---|---|
| int | Reasonable transmission time as % from the heartbeat interval |
ReceiveSpinningTimeout
The non-blocking receive spinning timeout (in microseconds) before the receiving thread enters into the blocking
wait mode.
Should not be greater than 1 sec. (the minimal KeepAliveInterval interval).
The default value is ReceiveSpinningTimeout.
Declaration
public int ReceiveSpinningTimeout { get; set; }
Property Value
| Type | Description |
|---|---|
| int | Receive spinning timeout (in microseconds) |
ReceivingThreadAffinity
Declaration
public int[] ReceivingThreadAffinity { get; set; }
Property Value
| Type | Description |
|---|---|
| int[] |
ReceivingThreadPolicy
Gets or sets the policy of the session receiving thread. Linux only.
Declaration
public LinuxThreadPolicy ReceivingThreadPolicy { get; set; }
Property Value
| Type | Description |
|---|---|
| LinuxThreadPolicy | The policy of the session receiving thread |
ReceivingThreadPriority
Gets or sets the priority of the session receiving thread. The default value is set by OS.
Declaration
public ThreadPriority ReceivingThreadPriority { get; set; }
Property Value
| Type | Description |
|---|---|
| ThreadPriority | The priority of the session receiving thread |
ReconnectAttempts
Number of attempts to restore the telecommunication link. The default value is ReconnectAttempts.
Declaration
public int ReconnectAttempts { get; set; }
Property Value
| Type | Description |
|---|---|
| int | Number of attempts to restore the telecommunication link |
ReconnectInterval
Time interval between attempts to restore the telecommunication link (in seconds). The default value is ReconnectInterval.
Declaration
public int ReconnectInterval { get; set; }
Property Value
| Type | Description |
|---|---|
| int | Time interval between attempts to restore the telecommunication link (in seconds) |
ReportNewMessagesWhileWaitingForMissedMessages
When the message gap is detected the "Resend Request" FIX Message is sent and Session state is changed to WaitForRetransmission. By default in this state the incoming new messages (without the PossDupFlag (tag #43) flag) are ignored because we expect them to be re-sent later again with the PossDupFlag flag. This property allows to change this behavior and report the new messages anyway.
Note: In this mode messages could be reported out of the original order: e.g. SeqNum could be: 3 (original), 4 (original), 2 (PossDupFlag='Y'), 3 (PossDupFlag='Y'), 4 (PossDupFlag='Y') and some messages could be received two times: first time without PossDupFlag='Y' and second time - with this flag.
Default value isfalse.
Declaration
public bool ReportNewMessagesWhileWaitingForMissedMessages { get; set; }
Property Value
| Type | Description |
|---|---|
| bool | Report new messages even when the message gap is detected and the reply on the "Resend Request" message is expected. |
ReuseEventArguments
Reuse event arguments.
Note: If it is turned on, then the client code must copy event arguments for using outside of event handlers.
The default value isfalse.
Declaration
public bool ReuseEventArguments { get; set; }
Property Value
| Type | Description |
|---|---|
| bool | Reuse event arguments |
ReuseInboundMessage
Reuse the same OnixS.SimpleBinaryEncoding.IMessage object for incoming messages.
Note: If it is turned on, then the client code must copy the OnixS.SimpleBinaryEncoding.IMessage object for using outside of inbound event handlers.
The default value isfalse.
Declaration
public bool ReuseInboundMessage { get; set; }
Property Value
| Type | Description |
|---|---|
| bool | Reuse the same OnixS.SimpleBinaryEncoding.IMessage object for incoming messages |
SecretKey
Declaration
public string SecretKey { get; }
Property Value
| Type | Description |
|---|---|
| string |
SendSpinningTimeout
The send spinning timeout (in microseconds) of the Send(IMessage) method to wait for the socket sending buffer availability in the spin loop mode before placing the message to the outgoing queue (to be sent later by the sending thread). Should not be greater than 1 sec (the minimal Heartbeat interval). The default value is SendSpinningTimeout.
Declaration
public int SendSpinningTimeout { get; set; }
Property Value
| Type | Description |
|---|---|
| int | The send spinning timeout (in microseconds) |
SendingThreadAffinity
Declaration
public int[] SendingThreadAffinity { get; set; }
Property Value
| Type | Description |
|---|---|
| int[] |
SendingThreadPriority
Gets or sets the priority of the session sending thread. The default value is set by OS.
Declaration
public ThreadPriority SendingThreadPriority { get; set; }
Property Value
| Type | Description |
|---|---|
| ThreadPriority | The priority of the session sending thread |
SessionId
Declaration
public SessionId SessionId { get; }
Property Value
| Type | Description |
|---|---|
| SessionId |
State
Session's state.
Declaration
public SessionState State { get; }
Property Value
| Type | Description |
|---|---|
| SessionState | Session's state |
StorageDirectory
Inbound and outbound FIX messages and session's state data are stored in this directory. The default value is StorageDirectory.
Declaration
public string StorageDirectory { get; set; }
Property Value
| Type | Description |
|---|---|
| string | Storage directory |
StorageId
The Id of the session storage.
Declaration
public string StorageId { get; }
Property Value
| Type | Description |
|---|---|
| string | Session storage id |
StorageType
Session's storage type.
Declaration
public SessionStorageType StorageType { get; }
Property Value
| Type | Description |
|---|---|
| SessionStorageType | Session's storage type. |
TcpNoDelay
Improve latency at the expense of throughput (disable/enable Nagle's algorithm). The default value is TcpNoDelay.
Declaration
public bool TcpNoDelay { get; set; }
Property Value
| Type | Description |
|---|---|
| bool | Improve latency at the expense of throughput (disable/enable Nagle's algorithm) |
UpdateSendingTime
Option to update the SendingTime (52) field in the outgoing message even if it is already set. The default value is UpdateSendingTime.
Declaration
public bool UpdateSendingTime { get; set; }
Property Value
| Type | Description |
|---|---|
| bool | Update the SendingTime (52) field in the outgoing message if it is already set |
Methods
BreakConnection(bool)
Breaks the FIXP connection non-gracefully (without the exchange of Terminate (MessageId=5) messages).
Declaration
public void BreakConnection(bool async = false)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | async | If |
Connect(string, int)
Declaration
public void Connect(string host, int port)
Parameters
| Type | Name | Description |
|---|---|---|
| string | host | |
| int | port |
Exceptions
| Type | Condition |
|---|---|
| CannotEstablishLinkException | The telecommunication link cannot be established |
| LinkErrorException | After sending the initial Logon message the telecommunication link error is detected |
| UnexpectedMessageTypeException | The first received message is not a Logon |
| UnexpectedSequenceNumberException | The first received message has an unexpected sequence number |
| ResponseTimeoutException | After sending the initial Logon message the acknowledgment Logon message has not been received during the timeout period. The timeout is calculated using the heartbeat value. |
CreateDecoder()
Create decoder instance to decode messages.
Declaration
public IDecoder CreateDecoder()
Returns
| Type | Description |
|---|---|
| IDecoder | New decoder object. |
CreateEncoder()
Create encoder instance to encode messages.
Declaration
public IEncoder CreateEncoder()
Returns
| Type | Description |
|---|---|
| IEncoder | New encoder object. |
Disconnect(bool)
Terminates the FIXP connection. The initial Terminate message is sent to the counterparty.
Declaration
public void Disconnect(bool async = false)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | async | If |
Disconnect(string, bool)
Declaration
public void Disconnect(string reason, bool async = false)
Parameters
| Type | Name | Description |
|---|---|---|
| string | reason | |
| bool | async | If |
Dispose()
Terminates the FIX Session, explicitly releases resource and removes the object from Garbage Collector.
Declaration
public void Dispose()
Dispose(bool)
Declaration
protected virtual void Dispose(bool disposing)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | disposing |
~Session()
Perform cleanup operations on unmanaged resources held by the current Session object before the object is destroyed.
Declaration
protected ~Session()
FindSentMessage(int)
Finds the sent message by the given message sequence number.
Declaration
public IMessage FindSentMessage(int messageSequenceNumber)
Parameters
| Type | Name | Description |
|---|---|---|
| int | messageSequenceNumber | Message sequence number |
Returns
| Type | Description |
|---|---|
| IMessage | Found message or |
Remarks
The number of available messages is limited by SentMessagesQueueMaxSize.
FlushSessionStorage()
Flushes all internal buffers of the underlying storage.
Declaration
public void FlushSessionStorage()
OnError(SessionErrorEventArgs)
Declaration
protected virtual void OnError(SessionErrorEventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| SessionErrorEventArgs | e |
OnFailover(FailoverEventArgs)
Declaration
protected virtual void OnFailover(FailoverEventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| FailoverEventArgs | e |
OnStateChanged(SessionStateChangeEventArgs)
Declaration
protected virtual void OnStateChanged(SessionStateChangeEventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| SessionStateChangeEventArgs | e |
OnWarning(SessionWarningEventArgs)
Declaration
protected virtual void OnWarning(SessionWarningEventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| SessionWarningEventArgs | e |
Reset(bool)
Resets local sequence numbers to 1, generates a new UUId, and backups log files.
NOTE: This method can be called only when the session is disconnected.
Declaration
public void Reset(bool startOfWeek = false)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | startOfWeek | if true then the PreviousUUID and PreviousSeqNum are reset to 0. |
Send(IMessage)
Sends the given application-level message.
Declaration
public void Send(IMessage message)
Parameters
| Type | Name | Description |
|---|---|---|
| IMessage | message |
Send(IEnumerable<IMessage>)
Declaration
public void Send(IEnumerable<IMessage> messages)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<IMessage> | messages |
ToString()
Returns a string that represents the current session.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string |
Overrides
WarmUp(IMessage, SocketFlags)
Warms the session up.
Declaration
public void WarmUp(IMessage message, SocketFlags sendingFlags = SocketFlags.None)
Parameters
| Type | Name | Description |
|---|---|---|
| IMessage | message | |
| SocketFlags | sendingFlags |
Events
BytesReceived
Declaration
public event BytesReceivedEventHandler BytesReceived
Event Type
| Type | Description |
|---|---|
| BytesReceivedEventHandler |
Error
Error condition is detected.
Declaration
public event EventHandler<SessionErrorEventArgs> Error
Event Type
| Type | Description |
|---|---|
| EventHandler<SessionErrorEventArgs> |
Failover
FaultToleranceIndicator is changed.
Declaration
public event EventHandler<FailoverEventArgs> Failover
Event Type
| Type | Description |
|---|---|
| EventHandler<FailoverEventArgs> |
InboundApplicationMessage
Application-level message is received from the counterparty.
Declaration
public event EventHandler<InboundMessageEventArgs> InboundApplicationMessage
Event Type
| Type | Description |
|---|---|
| EventHandler<InboundMessageEventArgs> |
InboundSessionMessage
Session-level message is received from the counterparty.
Declaration
public event EventHandler<InboundMessageEventArgs> InboundSessionMessage
Event Type
| Type | Description |
|---|---|
| EventHandler<InboundMessageEventArgs> |
MessageSending
Sent application-level message is about to be sent to the counterparty.
Declaration
public event Session.MessageSendingEventHandler MessageSending
Event Type
| Type | Description |
|---|---|
| Session.MessageSendingEventHandler |
NotApplied
NotApplied message is received, since the counterparty detects a sequence gap from the customer.
Declaration
public event EventHandler<NotAppliedEventArgs> NotApplied
Event Type
| Type | Description |
|---|---|
| EventHandler<NotAppliedEventArgs> |
StateChanged
Session state is changed.
Declaration
public event EventHandler<SessionStateChangeEventArgs> StateChanged
Event Type
| Type | Description |
|---|---|
| EventHandler<SessionStateChangeEventArgs> |
Warning
Warning condition is detected.
Declaration
public event EventHandler<SessionWarningEventArgs> Warning
Event Type
| Type | Description |
|---|---|
| EventHandler<SessionWarningEventArgs> |