public XElement BuildXML(QuickFix.Message msg,  MsgType msgType, DateTime? logTimeStamp = null, string origChkSum = null)
		{
			//Debug.WriteLine(" ~~~> " + msg.GetType().ToString());
			SessionID sessionID = msg.GetSessionID(msg);

			FIXClassInfo fixClass = null;
			if (msg.GetType() == typeof(QuickFix.Message))
			{
				var classes = fixClasses[msgType.ToString(), Utils.NormalizeFIXNameSpace(sessionID.BeginString)];
				if(classes != null && classes.Count>0)
					fixClass = classes[0];
			}

			//var root = new XElement(msg.GetType().ToString());
			var root = new XElement((fixClass!=null) ? fixClass.type.FullName : msg.GetType().ToString());
			root.Add(new XAttribute("MessageType", msgType.ToString()));
			root.Add(new XAttribute("Session", sessionID.ToString()));
			if(logTimeStamp.HasValue)
				root.Add(new XAttribute("LogTimeStamp", logTimeStamp.Value));	
			
			var header = new XElement(msg.Header.GetType().ToString());
			ProcessFieldMapToXML(header, msg.Header);
			root.Add(header);
			
			var body = new XElement(msg.GetType().ToString() + ".Body");
			ProcessFieldMapToXML(body, msg);
			root.Add(body);
			
			var trailer = new XElement(msg.Trailer.GetType().ToString());
			ProcessFieldMapToXML(trailer, msg.Trailer, origChkSum);
			root.Add(trailer);
			
			return root;
		}
Пример #2
0
        private void MessageDisplay(QuickFix.Message msg, SessionID sessionID, MessageDisplayer msgDisplayer)
        {
            if (msgDisplayer == MessageDisplayer.Sender)
            {
                DataContainer.form1.AppendSenderBox($@"=================={msg.GetType()}==================");
                DataContainer.form1.AppendSenderBox("@" + sessionID.ToString());
                var msgLst       = msg.ToList();
                var msgHeaderLst = msg.Header.ToList();

                foreach (var item in msgHeaderLst)
                {
                    DataContainer.form1.AppendSenderBox(Fix44XmlParser.getFieldName(item.Key.ToString()) + @": " + Fix44XmlParser.getFieldValueName(item.Key.ToString(), item.Value.ToString()));
                }
                foreach (var item in msgLst)
                {
                    DataContainer.form1.AppendSenderBox(Fix44XmlParser.getFieldName(item.Key.ToString()) + @": " + Fix44XmlParser.getFieldValueName(item.Key.ToString(), item.Value.ToString()));
                }
            }
            else if (msgDisplayer == MessageDisplayer.Receiver)
            {
                DataContainer.form1.AppendReceiverBox($@"=================={msg.GetType()}==================");
                DataContainer.form1.AppendReceiverBox("@" + sessionID.ToString());
                var msgLst       = msg.ToList();
                var msgHeaderLst = msg.Header.ToList();

                foreach (var item in msgHeaderLst)
                {
                    DataContainer.form1.AppendReceiverBox(Fix44XmlParser.getFieldName(item.Key.ToString()) + @": " + Fix44XmlParser.getFieldValueName(item.Key.ToString(), item.Value.ToString()));
                }
                foreach (var item in msgLst)
                {
                    DataContainer.form1.AppendReceiverBox(Fix44XmlParser.getFieldName(item.Key.ToString()) + @": " + Fix44XmlParser.getFieldValueName(item.Key.ToString(), item.Value.ToString()));
                }
            }
        }
Пример #3
0
        void IApplication.FromApp(FixMessage message, SessionID sessionId)
        {
            if (_Log.IsTraceEnabled)
            {
                _Log.Trace().PrintFormat("[{0}] <-< {1}", sessionId, message.PrettyPrint().Preformatted());
            }

            switch (message)
            {
            case Reject msg:
                Handle(msg);
                break;

            case ExecutionReport msg:
                Handle(msg);
                break;

            case OrderCancelReject msg:
                Handle(msg);
                break;

            default:
                _Log.Warn().PrintFormat("Unexpected message: {0}", message.GetType().Name);
                break;
            }
        }
Пример #4
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();
        }
Пример #5
0
 public void FromAdmin(QuickFix.Message message, QuickFix.SessionID session)
 {
     try
     {
         logger.Debug("RCV(Admin) <-- type[" + message.GetType().ToString() + "] msg[" + message.ToString() + "]");
     }
     catch (Exception ex)
     {
         logger.Error("FromAdmin(): " + ex.Message, ex);
     }
 }
Пример #6
0
 public void FromApp(Message message, SessionID sessionID)
 {
     Console.WriteLine("IN:  " + message);
     try
     {
         Crack(message, sessionID);
     }
     catch (UnsupportedMessageType)
     {
         Console.WriteLine("Unsupported message type: {0}", message.GetType());
     }
 }
Пример #7
0
 public virtual void ToApp(QuickFix.Message message, QuickFix.SessionID session)
 {
     try
     {
         logger.Debug("SND(App) --> type[" + message.GetType().ToString() + "] msg[" + message.ToString() + "]");
         //this.Crack(message, session);
     }
     catch (Exception ex)
     {
         logger.Error("ToApp(): " + ex.Message, ex);
     }
 }
        /*
         * //Sample
         * {
         *      "QuickFix.FIX44.ExecutionReport": {
         *  "MessageType":"QuickFix.FIX44.ExecutionReport",
         *  "Session":"FIX.4.4:BLP->MAP_GPSE_PRD",
         *  "LogTimeStamp":"2019-10-09T14:25:34.187Z",
         *  "Header": {
         *  }
         *  }
         * }
         */

        public string BuildJSON(QuickFix.Message msg, MsgType msgType, DateTime?logTimeStamp = null, string origChkSum = null)
        {
            //JObject jo = JObject.FromObject(fixMsg);
            //jo.Add("feeClass", "A");
            //string sJSON = jo.ToString();


            ////Debug.WriteLine(" ~~~> " + msg.GetType().ToString());
            SessionID sessionID = msg.GetSessionID(msg);

            FIXClassInfo fixClass = null;

            if (msg.GetType() == typeof(QuickFix.Message))
            {
                var classes = fixClasses[msgType.ToString(), Utils.NormalizeFIXNameSpace(sessionID.BeginString)];
                if (classes != null && classes.Count > 0)
                {
                    fixClass = classes[0];
                }
            }

            StringBuilder sb   = new StringBuilder();
            var           root = (fixClass != null) ? fixClass.type.FullName : msg.GetType().ToString();

            sb.Append("{");
            sb.Append($@"""{root}"":");
            sb.Append(FormatJSONPair("MessageType", msg.GetType().ToString()));
            sb.Append(FormatJSONPair("Session", sessionID.ToString()));
            sb.Append(FormatJSONPair("LogTimeStamp", logTimeStamp));

            ProcessFieldMapToJSON("Header", sb, msg.Header);
            ProcessFieldMapToJSON("Body", sb, msg);
            ProcessFieldMapToJSON("Trailer", sb, msg.Trailer, origChkSum);

            sb.Append("}");
            sb.Append("}");

            return(sb.ToString());
        }
Пример #9
0
 public virtual void ToAdmin(QuickFix.Message message, QuickFix.SessionID session)
 {
     try
     {
         logger.Debug("SND(Admin) --> type[" + message.GetType().ToString() + "] msg[" + message.ToString() + "]");
         //if (message.Header.GetField(QuickFix.Fields.Tags.MsgType) != QuickFix.Fields.MsgType.HEARTBEAT)
         //    this.Crack(message, session);
     }
     catch (Exception ex)
     {
         logger.Error("ToAdmin(): " + ex.Message, ex);
     }
 }
Пример #10
0
 public void FromApp(Message message, SessionID sessionID)
 {
     _messageCallback("IN:  " + message);
     try
     {
         Crack(message, sessionID);
     }
     catch (UnsupportedMessageType)
     {
         _messageCallback(
             string.Format("Unsupported message type: {0}", message.GetType()));
     }
 }
 protected RequestStateMachine(QuickFix.Message message, CancellationToken cancellationToken, IMessageHandler messageHandler, ILog log)
 {
     Message           = message;
     _messageHandler   = messageHandler;
     CancellationToken = cancellationToken;
     Id  = message.GetType().Name + Guid.NewGuid();
     Log = Log = log.CreateComponentScope(GetType().Name);
     cancellationToken.Register(() => TaskCompletionSource.TrySetCanceled(cancellationToken));
     if (cancellationToken.IsCancellationRequested)
     {
         TaskCompletionSource.TrySetCanceled(cancellationToken);
         Status = RequestStatus.Completed;
     }
 }
Пример #12
0
        public virtual void ToAdmin(QuickFix.Message message, QuickFix.SessionID session)
        {
            try
            {
                logger.Debug("SND(Admin) --> type[" + message.GetType().ToString() + "] msg[" + message.ToString() + "]");
                //if (message.Header.GetField(QuickFix.Fields.Tags.MsgType) != QuickFix.Fields.MsgType.HEARTBEAT)
                //    this.Crack(message, session);
                // Complementa a mensagem de logon com a senha
                if (message.GetType() == typeof(Logon))
                {
                    Logon message2 = (Logon)message;
                    if (_channelUmdfConfig.LogonPassword != "")
                    {
                        message2.Set(new QuickFix.Fields.RawData(_channelUmdfConfig.LogonPassword));
                        message2.Set(new QuickFix.Fields.RawDataLength(_channelUmdfConfig.LogonPassword.Length));
                        if (_channelUmdfConfig.NewPassword != null && _channelUmdfConfig.NewPassword.Length > 0)
                        {
                            QuickFix.Fields.StringField newPassword = new QuickFix.Fields.StringField(925, _channelUmdfConfig.NewPassword.Trim());
                            message2.SetField(newPassword);
                        }
                    }

                    message2.Set(new QuickFix.Fields.HeartBtInt(_channelUmdfConfig.HeartBtInt));
                    message2.Set(new QuickFix.Fields.EncryptMethod(0));
                    message2.Set(new QuickFix.Fields.ResetSeqNumFlag(_channelUmdfConfig.ResetOnLogon));
                }

                logger.Debug("ToAdmin(). Session id : " + session.ToString() + " Msg: " + message.GetType().ToString());

                //if (message.getHeader().getField(MsgType.FIELD) != QuickFix.MsgType.Heartbeat)
                //    this.crack(message, session);
            }
            catch (Exception ex)
            {
                logger.Error("ToAdmin(): " + ex.Message, ex);
            }
        }
Пример #13
0
        public void ToAdmin(QuickFix.Message message, SessionID sessionID)
        {
            // Faz o processamento
            try
            {
                string msgType = message.Header.GetString(35);
                logger.Debug("ToAdmin: " + msgType);

                // Complementa a mensagem de logon com a senha
                if (msgType.Equals(QuickFix.FIX42.Logon.MsgType))
                {
                    Logon message2 = (Logon)message;
                    if (ConfigurationManager.AppSettings["Passwd42"] != null)
                    {
                        message2.Set(new RawData(ConfigurationManager.AppSettings["Passwd42"].ToString()));
                        message2.Set(new RawDataLength(ConfigurationManager.AppSettings["Passwd42"].ToString().Length));
                    }

                    if (ConfigurationManager.AppSettings["CancelOnDisconnect"] != null &&
                        ConfigurationManager.AppSettings["CancelOnDisconnect"].ToString().ToUpper().Equals("N") &&
                        ConfigurationManager.AppSettings["CancelOnDisconnect"].ToString().ToUpper().Equals("FALSE"))
                    {
                        char codtype = ConfigurationManager.AppSettings["CancelOnDisconnect"].ToString()[0];
                        if (codtype >= '0' && codtype <= '3')
                        {
                            CharField field35002 = new CharField(35002, codtype);
                            message2.SetField(field35002);
                        }

                        IntField field35003 = new IntField(35003, 60000);
                        message2.SetField(field35003);
                    }
                    message2.Set(new HeartBtInt(30));
                    message2.Set(new EncryptMethod(0));
                    message2.Set(new ResetSeqNumFlag(ConfigurationManager.AppSettings["ResetSeqNum"].ToString().Equals("true")));
                }

                logger.Debug("toAdmin(). Session id : " + sessionID + " Msg: " + message.GetType().ToString());

                if (message.Header.GetString(35).Equals(QuickFix.FIX42.Heartbeat.MsgType) == false)
                {
                    Crack(message, sessionID);
                }
            }
            catch (Exception ex)
            {
                logger.Error("toAdmin() Erro: " + ex.Message, ex);
            }
        }
Пример #14
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();
            }
        }
Пример #15
0
        public virtual void FromApp(QuickFix.Message message, QuickFix.SessionID session)
        {
            try
            {
                if (logger.IsDebugEnabled)
                {
                    logger.Debug("RCV(App) <-- type[" + message.GetType().ToString() + "] msg[" + message.ToString() + "]");
                }

                this.Crack(message, session);
            }
            catch (Exception ex)
            {
                logger.Error("FromApp(): " + ex.Message, ex);
            }
        }
Пример #16
0
        public void ToAdmin(QuickFix.Message message, QuickFix.SessionID session)
        {
            // Faz o processamento
            try
            {
                // Complementa a mensagem de logon com a senha
                if (message.GetType() == typeof(Logon))
                {
                    Logon message2 = (Logon)message;
                    if (_config.LogonPassword != "")
                    {
                        message2.Set(new RawData(_config.LogonPassword));
                        message2.Set(new RawDataLength(_config.LogonPassword.Length));
                        if (_config.NewPassword != null && _config.NewPassword.Length > 0)
                        {
                            // message2.setString(925, _config.NewPassword.Trim());
                            NewPassword newpwd = new NewPassword(_config.NewPassword.Trim());
                            message2.SetField(newpwd);
                        }
                    }

                    if (_config.CancelOnDisconnect >= 0)
                    {
                        char codtype = _config.CancelOnDisconnect.ToString()[0];
                        if (codtype >= '0' && codtype <= '3')
                        {
                            message2.SetField(new CharField(35002, codtype));
                        }
                        if (_config.CODTimeout >= 0 && _config.CODTimeout <= 60)
                        {
                            message2.SetField(new IntField(35003, _config.CODTimeout * 1000));
                        }
                    }
                    message2.Set(new HeartBtInt(_config.HeartBtInt));
                    message2.Set(new EncryptMethod(0));
                    message2.Set(new ResetSeqNumFlag(_config.ResetSeqNum));
                }
                if (message.Header.GetField(Tags.MsgType) != MsgType.HEARTBEAT)
                {
                    this.Crack(message, session);
                }
            }
            catch (Exception ex)
            {
                logger.Error("toAdmin() Erro: " + ex.Message, ex);
            }
        }
Пример #17
0
        public void ToAdmin(QuickFix.Message message, SessionID sessionID)
        {
            // Faz o processamento
            try
            {
                string msgType = message.Header.GetString(35);
                logger.Debug("ToAdmin: " + msgType);

                if (msgType.Equals(QuickFix.FIX42.Logon.MsgType))
                {
                    Logon message2 = (Logon)message;
                    if (!string.IsNullOrEmpty(this.Password))
                    {
                        message2.Set(new RawData(this.Password));
                        message2.Set(new RawDataLength(this.Password.Length));
                    }
                    //if (!string.IsNullOrEmpty(this.CancelOnDisconnect))
                    //{
                    //    char codtype = this.CancelOnDisconnect[0];
                    //    if (codtype >= '0' && codtype <= '3')
                    //    {
                    //        CharField field35002 = new CharField(35002, codtype);
                    //        message2.SetField(field35002);
                    //    }
                    //    IntField field35003 = new IntField(35003, 10000);
                    //    message2.SetField(field35003);
                    //}
                    message2.Set(new HeartBtInt(30));
                    message2.Set(new EncryptMethod(0));
                    message2.Set(new ResetSeqNumFlag(this.ResetOnLogon));
                }

                logger.Debug("toAdmin(). Session id : " + sessionID + " Msg: " + message.GetType().ToString());
                if (message.Header.GetString(35).Equals(QuickFix.FIX42.Heartbeat.MsgType) == false)
                {
                    Crack(message, sessionID);
                }
            }
            catch (Exception ex)
            {
                logger.Error("toAdmin() Erro: " + ex.Message, ex);
            }
        }
Пример #18
0
 public void FromApp(Message message, SessionID sessionID)
 {
     _messageCallback("IN:  " + message);
     try
     {
         Crack(message, sessionID);
     }
     catch (UnsupportedMessageType)
     {
         _messageCallback(
             string.Format("Unsupported message type: {0}", message.GetType()));
     }
 }
Пример #19
0
 public virtual void fromAdmin(QuickFix.Message message, QuickFix.SessionID session)
 {
     try
     {
         logger.Debug("fromAdmin().Session id : " + session.ToString() + " Msg: " + message.GetType().ToString());
         this.crack(message, session);
     }
     catch (Exception ex)
     {
         logger.Error("fromApp() Erro: " + ex.Message, ex);
     }
 }
Пример #20
0
        public virtual void toAdmin(QuickFix.Message message, QuickFix.SessionID session)
        {
            // Faz o processamento
            try
            {
                logger.Debug("toAdmin(). Session id : " + session.ToString() + " Msg: " + message.GetType().ToString());

                if (message.getHeader().getField(MsgType.FIELD) != QuickFix.MsgType.Heartbeat)
                {
                    this.crack(message, session);
                }
            }
            catch (Exception ex)
            {
                logger.Error("toAdmin() Erro: " + ex.Message, ex);
            }
        }
Пример #21
0
        public virtual void toApp(QuickFix.Message message, QuickFix.SessionID session)
        {
            // Faz o processamento
            try
            {
                logger.Debug("toApp(). Session id : " + session.ToString() + " Msg: " + message.GetType().ToString());

                this.crack(message, session);
            }
            catch (Exception ex)
            {
                logger.Error("toApp() Erro: " + ex.Message, ex);
            }
        }