Example #1
0
 /// <summary>
 /// This implementation of the Send method forwards the
 /// specified FIX message to the underlying FIX session
 /// for transmission to the peer system.
 /// </summary>
 /// <param name="msg"></param>
 public void Send(VfxEngine.Fix.FixMessage msg)
 {
     _fixSession.HandleTxMessage(msg);
 }
        /// <summary>
        /// The HandleRxMessage method is invoked by the owner of an
        /// instance of a session to inform it that data has arrived
        /// from the peer system.
        /// </summary>
        /// <param name="mb">
        /// The message block that contains the data received from 
        /// the peer system the session is communicating with.
        /// </param>
        public void HandleRxMessage(VfxEngine.Ipc.VfxMsgBlock mb)
        {
            // REC: Attempt to parse an instance of a FIX message from
            // the raw data that was received over the endpoint, using
            // the default protocol version, if none of the configured
            // versions match the content:
            VfxFixParserResult fpr = _fixParser.Parse(Encoding.ASCII.GetString(mb.Buffer, 0, mb.Length()), null, null, this._axDefault);
            while (fpr.Status == VfxFixParserStatus.MsgComplete)
            {
                // REC: Adjust the read index in the message block
                // to compensate for the number of bytes parsed from
                // the incoming data stream:
                mb.RdIndex += fpr.Consumed;
                // REC: Crunch the message block to remove the data
                // that has already been parsed:
                mb.Crunch();

                // REC: Reset the timestamp that is used to determine
                // when the last message was received from the peer:
                this._lastRxTicks = DateTime.Now.Ticks;

                // REC: Determine if the message is a session layer
                // message and process it accordingly:
                FixField fldMsgType = fpr.Message.Header.GetField(35);
                if (fldMsgType != null)
                {
                    string strMsgType = fldMsgType.Content;
                    if (!string.IsNullOrEmpty(strMsgType))
                    {
                        switch (strMsgType)
                        {
                            case "A":
                                // Received a FIX logon message:
                                HandleSession_Logon(fpr.Message);
                                break;
                            case "0":
                                // Received a FIX heartbeat message:
                                HandleSession_Heartbeat(fpr.Message);
                                break;
                            case "1":
                                // Received a FIX test request:
                                HandleSession_TestRequest(fpr.Message);
                                break;
                            case "2":
                                // Received a FIX resend request:
                                HandleSession_Resend(fpr.Message);
                                break;
                            case "5":
                                // Received a FIX logout message:
                                HandleSession_Logout(fpr.Message);
                                break;
                            default:
                                // Received a message that should be
                                // routed to the session's owner:
                                HandleSession_Message(fpr.Message);
                                break;
                        }
                    }
                    else
                    {
                        // REC: If the session's identity hasn't been
                        // established yet, just throw an exception and
                        // let the session's owner shut it down:
                        if (_currentState == SessionStates.Session_Pending)
                        {
                            throw new ArgumentException("Initial message missing required field - FIX MsgType.");
                        }
                        else
                        {
                            // REC: The session has been established, so the
                            // session can send a reject message:
                        }
                    }
                }
                else
                {

                }

                // REC: Attempt to parse another message from
                // the buffer of data that has been received:
                fpr = _fixParser.Parse(Encoding.ASCII.GetString(mb.Buffer, 0, mb.Length()), null, null, this._axDefault);
            }

            // REC: If the parser couldn't extract a complete message
            // from the supplied buffer, determine what to do next:
            if (fpr.Status != VfxFixParserStatus.MsgComplete)
            {

            }
        }