FromString() публичный Метод

public FromString ( string msgstr, bool validate, DataDictionary sessionDD, DataDictionary appDD ) : void
msgstr string
validate bool
sessionDD DataDictionary
appDD DataDictionary
Результат void
Пример #1
1
        public void CheckSumTest()
        {
            string str1 = "8=FIX.4.2\x01" + "9=45\x01" + "35=0\x01" + "34=3\x01" + "49=TW\x01" +
                "52=20000426-12:05:06\x01" + "56=ISLD\x01";

            int chksum = 0;
            foreach (char c in str1)
                chksum += (int)c;
            chksum %= 256;

            str1 += "10=218\x01";  // checksum field
            Message msg = new Message();
            try
            {
                msg.FromString(str1, true, null, null, _defaultMsgFactory);
            }
            catch (InvalidMessage e)
            {
                Assert.Fail("Unexpected exception (InvalidMessage): " + e.Message);
            }
            Assert.That(msg.CheckSum(), Is.EqualTo(chksum));
        }
Пример #2
0
        public void Next(string msgStr)
        {
            try
            {
                this.Log.OnIncoming(msgStr);

                MsgType msgType     = Message.IdentifyType(msgStr);
                string  beginString = Message.ExtractBeginString(msgStr);

                Message message = msgFactory_.Create(beginString, msgType.Obj);
                message.FromString(
                    msgStr,
                    this.ValidateLengthAndChecksum,
                    this.SessionDataDictionary,
                    this.ApplicationDataDictionary);

                Next(message);
            }
            catch (InvalidMessage e)
            {
                this.Log.OnEvent(e.Message);

                try
                {
                    if (MsgType.LOGON.Equals(Message.IdentifyType(msgStr)))
                    {
                        Disconnect("Logon message is not valid");
                    }
                }
                catch (MessageParseError)
                { }

                throw e;
            }
        }
Пример #3
0
        public XElement BuildXMLFromString(string s, bool validateMsg = false, bool correctChks = true)
        {
            //"20150611-21:29:27.811 :"
            //8=FIX

            if (string.IsNullOrEmpty(s))
            {
                return(null);
            }

            if (s != null)
            {
                s = s.Trim();
            }


            DateTime?logTimeStamp = null;
            int      fixStart     = s.IndexOf("8=FIX");

            if (fixStart > 0)
            {
                string dateString = s.Substring(0, fixStart - 1);
                dateString = dateString.TrimEnd('\x01', ':', ' ');
                string   format = "yyyyMMdd-HH:mm:ss.fff";
                DateTime dateTime;
                if (DateTime.TryParseExact(dateString, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
                {
                    logTimeStamp = dateTime;
                }
                s = s.Substring(fixStart);
            }


            var msg = new QuickFix.Message();

            s = s.Trim('\n');
            s = s.Trim('\r');
            //msg.FromString(s, false, dataDictionary, dataDictionary, messageFactory);

            var    chksTuple = new Tuple <string, string>(string.Empty, string.Empty);
            string sOrigChks = null;

            if (correctChks)
            {
                if (!Utils.VerifyChecksum(ref s, out chksTuple, fixChecksum: true))
                {
                    sOrigChks = chksTuple.Item1;
                }
            }

            //---------------------------------------------------------------------------------------
            msg.FromString(s, validateMsg, sessionDataDictionary, dataDictionary, messageFactory);
            //---------------------------------------------------------------------------------------


            MsgType msgType = QuickFix.Message.IdentifyType(s);

            return(BuildXML(msg, msgType, logTimeStamp, sOrigChks));
        }
Пример #4
0
        internal Message Build()
        {
            Message message = _msgFactory.Create(_beginString, _defaultApplVerId, _msgType.Obj);

            message.FromString(
                _msgStr,
                _validateLengthAndChecksum,
                _sessionDD,
                _appDD,
                _msgFactory);
            _message = message;
            return(_message);
        }
Пример #5
0
        internal Message Build(Encoding encoding)
        {
            Message message = _msgFactory.Create(_beginString, _msgType.Obj);

            message.FromString(
                _msgStr,
                _validateLengthAndChecksum,
                _sessionDD,
                _appDD,
                _msgFactory,
                encoding);
            _message = message;
            return(_message);
        }
Пример #6
0
        internal Message RejectableMessage()
        {
            if (_message != null)
            {
                return(_message);
            }

            Message message = _msgFactory.Create(_beginString, _msgType.Obj);

            message.FromString(
                _msgStr,
                false,
                _sessionDD,
                _appDD,
                _msgFactory,
                true);
            return(message);
        }
Пример #7
0
        private void StartSendingMarketData()
        {
            StreamReader reader = new StreamReader(@"C:\Code\NigSEApplication\FIXT.1.1-PROD-XTRM.messages.current\log1.log");

            DefaultMessageFactory defaultMessageFactory = new DefaultMessageFactory();

            QuickFix.Message msg = new QuickFix.Message();

            while (!reader.EndOfStream)
            {
                string line = reader.ReadLine();

                string txt = "8=FIXT.1.19=00023635=W49=XTRM56=PROD34=452=20140820-07:26:00.726264=175=20140820262=*_148=MOBIL22=99762=EQTY268=5269=a326=1764=20140825269=s270=175.0000000269=u270=175.0000000269=x270=175.0000000269=y332=182.0000000333=106.000000010=143";


                // line.Substring(line.IndexOf("8=") - 1).Trim();

                msg.FromString(txt, false, null, null);
                string msgtype = msg.Header.GetString(35);

                if (msgtype == "W") //|| msgtype == "X")
                {
                    QuickFix.Message newmsg = new Message(txt);
                    if (Session.LookupSession(_currentSessionId).IsLoggedOn)
                    {
                        Session.LookupSession(_currentSessionId).ValidateLengthAndChecksum = false;
                        Session.SendToTarget(newmsg, _currentSessionId);
                    }
                    else
                    {
                        break;
                    }
                }
                Thread.Sleep(100);
            }
            reader.Close();
        }
Пример #8
0
        protected void NextResendRequest(Message resendReq)
        {
            if (!Verify(resendReq, false, false))
                return;
            try
            {
                int msgSeqNum = 0;
                if (!(this.IgnorePossDupResendRequests && resendReq.Header.IsSetField(Tags.PossDupFlag)))
                {
                    int begSeqNo = resendReq.GetInt(Fields.Tags.BeginSeqNo);
                    int endSeqNo = resendReq.GetInt(Fields.Tags.EndSeqNo);
                    this.Log.OnEvent("Got resend request from " + begSeqNo + " to " + endSeqNo);

                    if ((endSeqNo == 999999) || (endSeqNo == 0))
                    {
                        endSeqNo = state_.GetNextSenderMsgSeqNum() - 1;
                    }

                    if (!PersistMessages)
                    {
                        endSeqNo++;
                        int next = state_.GetNextSenderMsgSeqNum();
                        if (endSeqNo > next)
                            endSeqNo = next;
                        GenerateSequenceReset(resendReq, begSeqNo, endSeqNo);
                        return;
                    }

                    List<string> messages = new List<string>();
                    state_.Get(begSeqNo, endSeqNo, messages);
                    int current = begSeqNo;
                    int begin = 0;
                    foreach (string msgStr in messages)
                    {
                        Message msg = new Message();
                        msg.FromString(msgStr, true, this.SessionDataDictionary, this.ApplicationDataDictionary, msgFactory_);
                        msgSeqNum = msg.Header.GetInt(Tags.MsgSeqNum);

                        if ((current != msgSeqNum) && begin == 0)
                        {
                            begin = current;
                        }

                        if (IsAdminMessage(msg) && !(this.ResendSessionLevelRejects && msg.Header.GetString(Tags.MsgType) == MsgType.REJECT))
                        {
                            if (begin == 0)
                            {
                                begin = msgSeqNum;
                            }
                        }
                        else
                        {

                            initializeResendFields(msg);
                            if(!ResendApproved(msg, SessionID)) 
                            {
                                continue;
                            }

                            if (begin != 0)
                            {
                                GenerateSequenceReset(resendReq, begin, msgSeqNum);
                            }
                            Send(msg.ToString());
                            begin = 0;
                        }
                        current = msgSeqNum + 1;
                    }

                    int nextSeqNum = state_.GetNextSenderMsgSeqNum();
                    if (++endSeqNo > nextSeqNum)
                    {
                        endSeqNo = nextSeqNum;
                    }

                    if (begin == 0)
                    {
                        begin = current;
                    }

                    if (endSeqNo > begin)
                    {
                        GenerateSequenceReset(resendReq, begin, endSeqNo);
                    }
                }
                msgSeqNum = resendReq.Header.GetInt(Tags.MsgSeqNum);
                if (!IsTargetTooHigh(msgSeqNum) && !IsTargetTooLow(msgSeqNum))
                {
                    state_.IncrNextTargetMsgSeqNum();
                }

            }
            catch (System.Exception e)
            {
                this.Log.OnEvent("ERROR during resend request " + e.Message);
            }
        }
Пример #9
0
 public void FromStringTestWithNoDataDictionary()
 {
     string str1 = "8=FIX.4.2\x01" + "9=55\x01" + "35=0\x01" + "34=3\x01" + "49=TW\x01" +
         "52=20000426-12:05:06\x01" + "56=ISLD\x01" + "1=acct123\x01" + "10=123\x01";
     Message msg = new Message();
     try
     {
         msg.FromString(str1, true, null, null, _defaultMsgFactory);
     }
     catch (InvalidMessage e)
     {
         Assert.Fail("Unexpected exception (InvalidMessage): " + e.Message);
     }
     StringField f1 = new StringField(8);
     StringField f2 = new StringField(9);
     StringField f3 = new StringField(35);
     StringField f4 = new StringField(34);
     StringField f5 = new StringField(49);
     StringField f6 = new StringField(52);
     StringField f7 = new StringField(56);
     StringField f8 = new StringField(10);
     StringField f9 = new StringField(1);
     msg.Header.GetField(f1);
     msg.Header.GetField(f2);
     msg.Header.GetField(f3);
     msg.Header.GetField(f4);
     msg.Header.GetField(f5);
     msg.Header.GetField(f6);
     msg.Header.GetField(f7);
     msg.GetField(f9);
     msg.Trailer.GetField(f8);
     Assert.That(f1.Obj, Is.EqualTo("FIX.4.2"));
     Assert.That(f2.Obj, Is.EqualTo("55"));
     Assert.That(f3.Obj, Is.EqualTo("0"));
     Assert.That(f4.Obj, Is.EqualTo("3"));
     Assert.That(f5.Obj, Is.EqualTo("TW"));
     Assert.That(f6.Obj, Is.EqualTo("20000426-12:05:06"));
     Assert.That(f7.Obj, Is.EqualTo("ISLD"));
     Assert.That(f8.Obj, Is.EqualTo("123"));
     Assert.That(f9.Obj, Is.EqualTo("acct123"));
 }
Пример #10
0
        public void issue95()
        {
            // Parser screws up on triple-nested groups.  Contributes to ResendRequest failures.
            string msgStr = String.Join(Message.SOH, new string[]{
                "8=FIX.4.4","9=999","35=R","34=6","49=sendercompid","52=20130225-10:44:59.149","56=targetcompid", //headers
                    "131=quotereqid",
                    "146=1", // NoRelatedSym
                        "55=ABC","65=CD","48=securityid","22=1", // group
                        "711=1", // NoUnderlyings
                            "311=underlyingsymbol","312=WI","309=underlyingsecurityid","305=1",
                "10=999",""
            });

            var dd = new QuickFix.DataDictionary.DataDictionary();
            dd.Load("../../../spec/fix/FIX44.xml");

            Message msg = new Message();
            msg.FromString(msgStr, false, dd, dd, _defaultMsgFactory);

            // make sure no fields were dropped in parsing
            Assert.AreEqual(msgStr.Length, msg.ToString().Length);

            // make sure repeating groups are not rearranged
            // 1 level deep
            StringAssert.Contains(String.Join(Message.SOH, new string[] { "55=ABC", "65=CD", "48=securityid", "22=1" }), msg.ToString());
            // 2 levels deep
            StringAssert.Contains(String.Join(Message.SOH, new string[] { "311=underlyingsymbol", "312=WI", "309=underlyingsecurityid", "305=1" }), msg.ToString());
        }
Пример #11
0
        public void ReverseRoute()
        {
            string str1 = "8=FIX.4.2\x01" + "9=55\x01" + "35=0\x01" + "34=3\x01" + "49=TW\x01" +
                "52=20000426-12:05:06\x01" + "56=ISLD\x01" + "1=acct123\x01" + "10=123\x01";
            Message msg = new Message();
            try
            {
                msg.FromString(str1, true, null, null, _defaultMsgFactory);
            }
            catch (InvalidMessage e)
            {
                Assert.Fail("Unexpected exception (InvalidMessage): " + e.Message);
            }
            Header header = new Header();
            header.SetField(new BeginString("FIX.4.2"));
            header.SetField(new SenderCompID("SENDER"));
            header.SetField(new SenderSubID("SENDERSUB"));
            header.SetField(new SenderLocationID("SENDERLOC"));
            header.SetField(new TargetCompID("TARGET"));
            header.SetField(new TargetSubID("TARGETSUB"));
            header.SetField(new TargetLocationID("TARGETLOC"));

            msg.ReverseRoute(header);
            
            Assert.That(msg.Header.GetString(Tags.BeginString), Is.EqualTo("FIX.4.2"));
            Assert.That(msg.Header.GetString(Tags.TargetCompID), Is.EqualTo("SENDER"));
            Assert.That(msg.Header.GetString(Tags.TargetSubID), Is.EqualTo("SENDERSUB"));
            Assert.That(msg.Header.GetString(Tags.TargetLocationID), Is.EqualTo("SENDERLOC"));
            Assert.That(msg.Header.GetString(Tags.SenderCompID), Is.EqualTo("TARGET"));
            Assert.That(msg.Header.GetString(Tags.SenderSubID), Is.EqualTo("TARGETSUB"));
            Assert.That(msg.Header.GetString(Tags.SenderLocationID), Is.EqualTo("TARGETLOC"));
        }
Пример #12
0
        public void ToXMLTest()
        {
            string str1 = "8=FIX.4.2\x01" + "9=55\x01" + "35=0\x01" + "34=3\x01" + "49=TW\x01" +
                "52=20000426-12:05:06\x01" + "56=ISLD\x01" + "1=acct123\x01" + "10=123\x01";
            Message msg = new Message();
            try
            {
                msg.FromString(str1, true, null, null, _defaultMsgFactory);
            }
            catch (InvalidMessage e)
            {
                Assert.Fail("Unexpected exception (InvalidMessage): " + e.Message);
            }

            string xmlDoc = msg.toXML();
            XDocument doc = null;
            try
            {
                doc = XDocument.Parse(xmlDoc);
            }
            catch (Exception e)
            {
                Assert.Fail("Badly formed XML generated: " + e.Message);
            }

            var fields = doc.Descendants("message").Descendants("body")
                .Select(field =>
                    new
                    {
                        number = field.Descendants("field").Attributes("number").Single().Value,
                        value = field.Descendants("field").Single().Value
                    })
                    .ToList();

            foreach (var elem in fields)
            {
                int number = 0;
                if (int.TryParse(elem.number.ToString(), out number) == false)
                {
                    Assert.Fail("should be number " + elem.number.ToString() + " " + elem.value.ToString());
                }
                else
                {
                    string value = msg.GetField(number);
                    Assert.That(value, Is.EqualTo(elem.value));
                }
            }

        }
Пример #13
0
        public void TestNewParser()
        {
            HiPerfTimer timer = new HiPerfTimer();
            string fix = GenRandomFIXString();

            const int times = 50000;
            timer.Start();
            for (int i = 0; i < times; i++)
            {
                Message m = new Message();
                m.FromString(fix);
            }
            timer.Stop();
            Console.WriteLine("Total per second [new parser]: " + ((1 / timer.Duration) * times).ToString());
        }
        public string BuildJSONFromString(string s, bool validateMsg = false, bool correctChks = true)
        {
            string   sJSON        = string.Empty;
            DateTime?logTimeStamp = null;
            int      fixStart     = s.IndexOf("8=FIX");

            if (fixStart > 0)
            {
                string dateString = s.Substring(0, fixStart - 1);
                dateString = dateString.TrimEnd('\x01', ':', ' ');
                string   format = "yyyyMMdd-HH:mm:ss.fff";
                DateTime dateTime;
                if (DateTime.TryParseExact(dateString, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
                {
                    logTimeStamp = dateTime;
                }
                s = s.Substring(fixStart);
            }

            var msg = new QuickFix.Message();

            var    chksTuple = new Tuple <string, string>(string.Empty, string.Empty);
            string sOrigChks = null;

            if (correctChks)
            {
                if (!Utils.VerifyChecksum(ref s, out chksTuple, fixChecksum: true))
                {
                    sOrigChks = chksTuple.Item1;
                }
            }

            //---------------------------------------------------------------------------------------
            msg.FromString(s, validateMsg, sessionDataDictionary, dataDictionary, messageFactory);
            //---------------------------------------------------------------------------------------


            MsgType msgType = QuickFix.Message.IdentifyType(s);

            //Very inefficient. Need to rewrite to build JSON myself.
            sJSON = BuildJSON(msg, msgType, logTimeStamp, sOrigChks);

            //sJSON = JsonConvert.SerializeObject(msg);

            //string sJSON = JsonConvert.SerializeXmlNode(xElem.GetXmlNode());
            //XElement xElem = BuildXML(msg, msgType, logTimeStamp, sOrigChks);
            //=================================================================
            return(sJSON);

            //JTokenWriter writer = new JTokenWriter();
            //writer.WriteStartObject();
            //writer.WritePropertyName("name1");
            //writer.WriteValue("value1");
            //writer.WritePropertyName("name2");
            //writer.WriteStartArray();
            //writer.WriteValue(1);
            //writer.WriteValue(2);
            //writer.WriteEndArray();
            //writer.WriteEndObject();

            //JObject o = (JObject)writer.Token;

            //return o.ToString();
        }