/// <summary> /// The HandleSession_TestRequest method is invoked to /// handle a test request that has been received from the /// peer that the session is interacting with. /// </summary> /// <param name="msg"> /// The FIX test request received from the peer. /// </param> private void HandleSession_TestRequest(FixMessage msg) { if (_currentState == SessionStates.Session_Opened) { // REC: Dispatch the administrative message to the // session's callback handler: _handler.OnSessionRxAdmMessage(this, msg); // REC: Construct a response message to the test // request and dispatch it to the peer: FixMessage msgResponse = _fixAssembler.CreateMessage(_sxVersion, _axVersion, "0"); if (msgResponse != null) { // REC: Retrieve the test request token from // the incoming request and assign it to the // outbound response message: FixField fldTestReqID = msg.GetField(112); if (fldTestReqID != null) { if (!string.IsNullOrEmpty(fldTestReqID.Content)) { msgResponse.AddField(new FixField(112, fldTestReqID.Content)); } } Dispatch_AdmMessage(msgResponse); } } else { } }
/// <summary> /// The HandleSession_Logon method is invoked to handle /// a logon message that has been received from the peer /// session that this session is communicating with. /// </summary> /// <param name="msg"> /// The FIX logon message received from the peer. /// </param> private void HandleSession_Logon(FixMessage msg) { // REC: Ensure that we're in the appropriate state // to handle a logon message: if (_currentState == SessionStates.Session_Pending || _currentState == SessionStates.Session_Closed) { // REC: Retrieve the FIX SenderCompID of the peer // from the logon message: FixField fldSenderCompID = msg.Header.GetField(49); if (fldSenderCompID != null) { // REC: The SenderCompID from the peer becomes the // session's TargetCompID for outgoing messages: _fixTargetCompID = fldSenderCompID.Content; // REC: Now that the FIX SenderCompID of the peer // session is known, it is used to construct the // identifier for the session - used to retrieve // the session's details from the database: _sessionId = string.Format("{0}-{1}", _fixSenderCompID, _fixTargetCompID); // REC: Attempt to retrieve the session details // from the session database: if (_fixDatabase != null) { // REC: Note that once a session record is acquired // from the database, it must be released when it is // no longer needed by the session instance... _sessionRecord = _fixDatabase.AcquireSession(_sessionId); if (this._resetSequence == true) { _sessionRecord.RxSequence = 1; _sessionRecord.TxSequence = 1; } } // REC: Register the peer session's SenderCompID as // the TargetCompID for outgoing messages: _fixAssembler.SetField(new FixField(56, _fixTargetCompID)); // REC: Assemble the response message: FixMessage response = _fixAssembler.CreateMessage(_sxVersion, _axVersion, "A"); // REC: Handle the sequence number reset flag // if it is present in the logon message: FixField fieldReset = msg.GetField(141); if (fieldReset != null) { response.AddField(new FixField(141, "Y")); } // REC: Transition to the opened state: _currentState = SessionStates.Session_Opened; // REC: Notify the session's owner that the peer // session has sent the logon request: _handler.OnSessionLogon(this, msg); // REC: Dispatch the administrative message out // to the session's owner: Dispatch_AdmMessage(response); } else { // REC: Throw an exception since the session has not // yet been established and there will be no handler // at the application level that can deal with this: throw new ArgumentException("Logon message missing required field - SenderCompID."); } } else { // REC: Notify the session handler that an // administrative message has been received // from the peer session: _handler.OnSessionRxAdmMessage(this, msg); // REC: Throw an exception that indicates the // session is not in the appropriate state to // handle the received message: //throw new InvalidOperationException("Session state invalid for received message."); } }