Represents a FIX message
Inheritance: FieldMap
示例#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 TestParsePerformance()
        {
            string fix = GenRandomFIXString();

            HiPerfTimer timer = new HiPerfTimer();
            timer.Start();

            const int numMsgs = 50000;

            for (int i = 0; i < numMsgs; i++)
            {
                Message m = new Message();
                MakeMessage(m, fix);
            }
            timer.Stop();

            Console.WriteLine("Total per second: " + ((1 / timer.Duration) * numMsgs).ToString());

            // Test message creation latency.

            timer.Start();
            Message newMsg = new Message();
            MakeMessage(newMsg, fix);
            timer.Stop();

            Console.WriteLine(
                String.Format("Latency for parsing one FIX message in microseconds: {0}", (timer.Duration * 1000000).ToString()));
        }
示例#3
0
        public void MakeMessage(Message m, string fix)
        {
            idx = 0; prevIdx = 0;

            // Handle first field differently, no SOH at start.
            StringField sf = new StringField(0);
            idx = fix.IndexOf('\x01');
            if (idx != -1)
            {
                field = fix.Substring(prevIdx, (idx - prevIdx));
                tagIndex = field.IndexOf('=');

                sf.Tag = IntParse(field.Substring(0, tagIndex));
                sf.Obj = field.Substring(tagIndex + 1);
                m.setField(sf);
            }
            else return;

            while (idx != -1)
            {
                prevIdx = idx;
                idx = fix.IndexOf('\x01', prevIdx + 1);

                if (idx == -1) break;

                StringField sf2 = new StringField(0);
                field = fix.Substring(prevIdx + 1, (idx - prevIdx) - 1);
                tagIndex = field.IndexOf('=');

                sf2.Tag = IntParse(field.Substring(0, tagIndex));
                sf2.Obj = field.Substring(tagIndex + 1);
                m.setField(sf2);
            }
        }
        public Message Create(string beginString, string msgType)
        {
            IMessageFactory f = null;

            // FIXME: This is a hack.  FIXT11 could mean 50 or 50sp1 or 50sp2.
            // We need some way to choose which 50 version it is.
            // Choosing 50 here is not adequate.
            if (beginString.Equals(FixValues.BeginString.FIXT11))
            {
                if (!Message.IsAdminMsgType(msgType))
                    f = _factories[FixValues.BeginString.FIX50];
            }

            if(f != null)
                return f.Create(beginString, msgType);

            if (_factories.ContainsKey(beginString) == false)
            {
                Message m = new Message();
                m.Header.SetField(new StringField(QuickFix.Fields.Tags.MsgType, msgType));
                return m;
            }

            f = _factories[beginString];
            return f.Create(beginString, msgType);
        }
示例#5
0
 public void ToAdmin(Message message, SessionID sessionID)
 {
     if (message.Header.GetField(Tags.MsgType) == MsgType.LOGON)
     {
         message.SetField(new QuickFix.Fields.Username("batman"));
         message.SetField(new QuickFix.Fields.Password("gotham123"));
     }
 }
示例#6
0
 public void fromAdmin(Message message, SessionID sessionID)
 {
     if (!isTimerAdjusted)
     {
         SendingTime sendingTime = new SendingTime();
         message.getHeader().getField(sendingTime);
         Utils.AdjustTime(sendingTime.getValue());
         isTimerAdjusted = true;
     }
 }
示例#7
0
 public void FromApp(Message message, SessionID sessionID)
 {
     OnMessage(message, sessionID);
     string msgType = message.Header.GetString(Tags.MsgType);
     switch (msgType) {
         case "8":
             OnExecutionReport((QuickFix.FIX42.ExecutionReport)message);
             break;
     }
 }
示例#8
0
        public void Crack(Message message, SessionID sessionID)
        {
            Type messageType = message.GetType();
            MethodInfo handler = null;

            if (_handlerMethods.TryGetValue(messageType, out handler))
                handler.Invoke(this, new object[] { message, sessionID });
            else
                throw new UnsupportedMessageType();
        }
示例#9
0
 public void FromApp(Message message, SessionID sessionID)
 {
     string msgType = message.Header.GetString(Tags.MsgType);
     switch (msgType) {
         case "V":
             OnMessage(((QuickFix.FIX42.MarketDataRequest)message), sessionID);
             break;
         case "D":
             OnMessage(((QuickFix.FIX42.NewOrderSingle)message), sessionID);
             break;
     }
 }
示例#10
0
 internal Message Build()
 {
     Message message = _msgFactory.Create(_beginString, _msgType.Obj);
     message.FromString(
         _msgStr,
         _validateLengthAndChecksum,
         _sessionDD,
         _appDD,
         _msgFactory);
     _message = message;
     return _message;
 }
示例#11
0
 public void fromApp(Message message, SessionID sessionID)
 {
     try
     {
         crack(message, sessionID);
     }
     catch (UnsupportedMessageType exception)
     {
         Console.WriteLine("fromApp " + exception);
         Console.WriteLine("fromApp " + message);
     }
 }
示例#12
0
        public override void fromAdmin(Message message, SessionID sessionID)
        {
            base.fromAdmin(message, sessionID);

            if ((message is QuickFix42.Logout || message is QuickFix42.Reject) && message.isSetField(QuickFix.Text.FIELD))
            {
                Console.WriteLine(message.getString(QuickFix.Text.FIELD));
            }

            if (message is QuickFix42.Logout)
            {
                Disconnect();
            }
        }
示例#13
0
 public void FromApp(Message message, SessionID sessionID)
 {
     try
     {
         Crack(message, sessionID);
     }
     catch (Exception ex)
     {
         string s = "==Cracker exception==\n";
         s += ex.ToString() + "\n";
         s += ex.StackTrace;
         Puts(s);
     }
 }
示例#14
0
 public void FromApp(Message message, SessionID sessionID)
 {
     Console.WriteLine("IN:  " + message.ToString());
     try
     {
         Crack(message, sessionID);
     }
     catch (Exception ex)
     {
         Console.WriteLine("==Cracker exception==");
         Console.WriteLine(ex.ToString());
         Console.WriteLine(ex.StackTrace);
     }
 }
        public Message Create(string beginString, string msgType)
        {
            // TODO: if FIXT11 and non-admin message, use FIX50

            if (_factories.ContainsKey(beginString) == false)
            {
                Message m = new Message();
                m.Header.SetField(new StringField(QuickFix.Fields.Tags.MsgType, msgType));
                return m;
            }

            IMessageFactory f = _factories[beginString];
            return f.Create(beginString, msgType);
        }
示例#16
0
        /// <summary>
        /// Process ("crack") a FIX message and call the registered handlers for that type, if any
        /// </summary>
        /// <param name="message"></param>
        /// <param name="sessionID"></param>
        public void Crack(Message message, SessionID sessionID)
        {
            Type messageType = message.GetType();

            Action<Message, SessionID> onMessage = null;

            if (_callCache.TryGetValue(messageType, out onMessage))
            {
                onMessage(message, sessionID);
            }
            else
            {
                throw new UnsupportedMessageType();
            }
        }
示例#17
0
        protected void ProcessNOS(Message message, SessionID sessionID)
        {
            Message echo = new Message(message);

            bool possResend = false;
            if (message.Header.IsSetField(QuickFix.Fields.Tags.PossResend))
                possResend = message.Header.GetBoolean(QuickFix.Fields.Tags.PossResend);

            KeyValuePair<string, SessionID> pair = new KeyValuePair<string, SessionID>(message.GetField(QuickFix.Fields.Tags.ClOrdID), sessionID);
            if (possResend && clOrdIDs_.Contains(pair))
                return;
            clOrdIDs_.Add(pair);

            Session.SendToTarget(echo, sessionID);
        }
示例#18
0
 public bool SendToTarget(Message message, SessionID sessionID)
 {
     try
     {
         return Session.SendToTarget(message, sessionID);
     }
     catch (SessionNotFound ex)
     {
         _messageCallback("==session not found exception!==");
         _messageCallback(ex.ToString());
     }
     catch (Exception ex)
     {
         _messageCallback(ex.ToString());
     }
     return false;
 }
示例#19
0
 public void FromApp(Message message, SessionID sessionID)
 {
     try
     {
         string msgType = message.Header.GetField(QuickFix.Fields.Tags.MsgType);
         log_.OnEvent("Got message " + msgType);
         Crack(message, sessionID);
     }
     catch (QuickFix.UnsupportedMessageType)
     {
         throw;
     }
     catch (System.Exception e)
     {
         log_.OnEvent("FromApp: " + e.ToString() + " while processing msg (" + message.ToString() + ")");
     }
 }
示例#20
0
        public void toAdmin(Message message, SessionID sessionID)
        {
            // This is only for the TT dev environment.  The production FIX Adapter does not require a password
            MsgType msgType = new MsgType();
            message.getHeader().getField(msgType);

            TargetCompID targetCompID = new TargetCompID();
            message.getHeader().getField(targetCompID);

            if (msgType.ToString() == MsgType.Logon &&
                (targetCompID.ToString() == "TTDEV9P" || targetCompID.ToString() == "TTDEV9O"))
            {
                const string password = "******";
                RawData rawData = new RawData(password);
                message.getHeader().setField(rawData);
            }
            // End TT Dev environment case
        }
示例#21
0
        public void ToApp(Message message, SessionID sessionID)
        {
            try
            {
                bool possDupFlag = false;
                if (message.Header.IsSetField(QuickFix.Fields.Tags.PossDupFlag))
                {
                    possDupFlag = QuickFix.Fields.Converters.BoolConverter.Convert(
                        message.Header.GetField(QuickFix.Fields.Tags.PossDupFlag)); /// FIXME
                }
                if (possDupFlag)
                    throw new DoNotSend();
            }
            catch (FieldNotFoundException)
            { }

            Console.WriteLine();
            Console.WriteLine("OUT: " + message.ToString());
        }
示例#22
0
        public void EnumeratorTest()
        {
            Message msg = new Message("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");

            int numHeaderFields = 0;
            foreach (KeyValuePair<int, QuickFix.Fields.IField> kvp in msg.Header)
                ++numHeaderFields;
            Assert.AreEqual(7, numHeaderFields);

            int numTrailerFields = 0;
            foreach (KeyValuePair<int, QuickFix.Fields.IField> kvp in msg.Trailer)
                ++numTrailerFields;
            Assert.AreEqual(1, numTrailerFields);

            int numBodyFields = 0;
            foreach (KeyValuePair<int, QuickFix.Fields.IField> kvp in msg)
                ++numBodyFields;
            Assert.AreEqual(1, numBodyFields);
        }
示例#23
0
        static void Main( string[] args )
        {
            try
            {
            Message message = new Message("jh");
            message.Dispose();
            }
            catch( InvalidMessage e )
            {
            Console.WriteLine( e.Message );
            }

            GC.Collect();
            return;

            if ( args.Length != 1 )
            {
              Console.WriteLine( "usage: executor_csharp FILE." );
              return ;
            }

            try
            {
              SessionSettings settings = new SessionSettings( args[ 0 ] );
              Application application = new Application();
              FileStoreFactory storeFactory = new FileStoreFactory( settings );
              ScreenLogFactory logFactory = new ScreenLogFactory( settings );
              MessageFactory messageFactory = new DefaultMessageFactory();
              SocketAcceptor acceptor
            = new SocketAcceptor( application, storeFactory, settings, logFactory, messageFactory );

              acceptor.start();
              Console.WriteLine("press <enter> to quit");
              Console.Read();
              acceptor.stop();
            }
            catch ( Exception e )
            {
              Console.WriteLine( e );
            }
        }
示例#24
0
        public Message Create(string beginString, string msgType)
        {
            IMessageFactory f = null;
            if (beginString.Equals(FixValues.BeginString.FIXT11))
            {
                if (!Message.IsAdminMsgType(msgType))
                    f = _factories[FixValues.BeginString.FIX50];
            }

            if(f != null)
                return f.Create(beginString, msgType);

            if (_factories.ContainsKey(beginString) == false)
            {
                Message m = new Message();
                m.Header.SetField(new StringField(QuickFix.Fields.Tags.MsgType, msgType));
                return m;
            }

            f = _factories[beginString];
            return f.Create(beginString, msgType);
        }
示例#25
0
        private void Trace(Message message)
        {
            var text = "\r\n" + string.Join(" | ", message.Select(f => f.Key + "=" + f.Value));

            Log(text);
        }
示例#26
0
 public void ToApp(Message message, SessionID sessionId)
 {
     Trace(message);
 }
示例#27
0
        protected void GenerateBusinessMessageReject(Message message, int err, int field)
        {
            string msgType = message.Header.GetString(Tags.MsgType);
            int msgSeqNum = message.Header.GetInt(Tags.MsgSeqNum);
            string reason = FixValues.BusinessRejectReason.RejText[err];
            Message reject;
            if (this.SessionID.BeginString.CompareTo(FixValues.BeginString.FIX42) >= 0)
            {
                reject = msgFactory_.Create(this.SessionID.BeginString, MsgType.BUSINESS_MESSAGE_REJECT);
                reject.SetField(new RefMsgType(msgType));
                reject.SetField(new BusinessRejectReason(err));
            }
            else
            {
                reject = msgFactory_.Create(this.SessionID.BeginString, MsgType.REJECT);
                char[] reasonArray = reason.ToLower().ToCharArray();
                reasonArray[0] = char.ToUpper(reasonArray[0]);
                reason = new string(reasonArray);
            }
            InitializeHeader(reject);
            reject.SetField(new RefSeqNum(msgSeqNum));
            state_.IncrNextTargetMsgSeqNum();

            reject.SetField(new Text(reason));
            Log.OnEvent("Reject sent for Message: " + msgSeqNum + " Reason:" + reason);
            SendRaw(reject, 0);
        }
示例#28
0
        protected bool DoTargetTooLow(Message msg, int msgSeqNum)
        {
            bool possDupFlag = false;
            if (msg.Header.IsSetField(Fields.Tags.PossDupFlag))
                possDupFlag = msg.Header.GetBoolean(Fields.Tags.PossDupFlag);

            if (!possDupFlag)
            {
                string err = "MsgSeqNum too low, expecting " + state_.GetNextTargetMsgSeqNum() + " but received " + msgSeqNum;
                GenerateLogout(err);
                throw new QuickFIXException(err);
            }

            return DoPossDup(msg);
        }
示例#29
0
 public void fromAdmin(QuickFix.Message value, SessionID session)
 {
     // Console.WriteLine("Got message from Admin" + value.ToString());
 }
示例#30
0
 //发送应用消息到网关(比如下单,撤单,查询相关消息等)
 public void toApp(QuickFix.Message message, SessionID sessionID)
 {
     Fix.Out(message);
 }
示例#31
0
 public void FromApp(Message msg, SessionID sessionID)
 {
     //Crack(msg, sessionID);
     l.Info("FromApp: " + msg.Header.GetString(Tags.MsgType));
 }
示例#32
0
 public void FromAdmin(Message msg, SessionID sessionID)
 {
     Console.WriteLine("FromAdmin: " + msg.Header.GetString(Tags.MsgType));
 }
示例#33
0
 public void FromApp(Message message, SessionID sessionID)
 {
     Trace(message);
 }
示例#34
0
 public void toApp(QuickFix.Message value, QuickFix.SessionID session)
 {
     //  Console.WriteLine("Called toApp :" + value.ToString());
 }
示例#35
0
 //从网关返回的Admin消息
 public void fromAdmin(QuickFix.Message message, SessionID sessionID)
 {
     crack(message, sessionID);
     Fix.Out(message);
 }
示例#36
0
 protected bool SendMessageToSession(QuickFix.Message msg)
 {
     return(sessionList.Count > 0 && msg != null && Session.sendToTarget(msg, sessionList[0]));
 }
示例#37
0
 public void ToAdmin(Message message, SessionID sessionID)
 {
     Trace(message);
 }
        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();
        }