Beispiel #1
0
 public void ProcessNews(QuickFix.Message msg, SessionID sessionID)
 {
     if (msg.IsSetField(QuickFix.Fields.Tags.Headline) && (msg.GetString(QuickFix.Fields.Tags.Headline) == "STOPME"))
     {
         if (this.StopMeEvent != null)
         {
             StopMeEvent();
         }
     }
     else
     {
         Echo(msg, sessionID);
     }
 }
        public void ProcessMessage(QuickFix.Message msg, bool isIncoming)
        {
            string clordid = msg.GetString(11);

            if (TestManager.Instance.IsCancelled)
            {
                Console.WriteLine("Ignoring inbound message - Test cancelled by user:{0}{1}", System.Environment.NewLine, msg.ToString());
                Console.ReadKey();
                if (EndOfScenarioEvent != null)
                {
                    EndOfScenarioEvent();
                }
            }
            else if (!string.IsNullOrEmpty(clordid) && !((List <string>)ConfigurationSingleton.Instance.GetIDInUseList()).Contains(clordid))
            {
                Console.WriteLine("Ignoring inbound message - unknown ClOrdID:{0}{1}", System.Environment.NewLine, msg.ToString());
                Console.WriteLine();
            }
            else
            {
                Debug.WriteLine("Q:{0} Incoming:{1} - {2}", outQ.Count.ToString(), isIncoming.ToString(), msg.ToString());

                //Console.WriteLine("Message received: {0}", msg.ToString());
                if (isIncoming)
                {
                    if (outQ.Count > 0 && outQ.Peek().Direction == MessageDirection.INBOUND)
                    {
                        RawMessage rm = outQ.Dequeue();
                        Debug.WriteLine("Q:{0} Incoming:{1} - {2}", outQ.Count.ToString(), isIncoming.ToString(), msg.ToString());
                        //Console.WriteLine();
                        //Console.WriteLine("Received: {0}", msg.ToString());
                        //Console.WriteLine("Expected: {0}", rm.Message);

                        MessageResult mr = new MessageResult(rm.Message, msg.ToString());
                        ProcessResult(mr);
                        results.Add(mr);
                    }

                    if (outQ.Count == 0)
                    {
                        ProcessResults();
                    }
                }

                SendNext();
            }
        }
Beispiel #3
0
        public void Next(Message message)
        {
            if (!IsSessionTime)
            {
                Reset();
                return;
            }

            Header header = message.Header;
            string msgType = "";

            try
            {
                msgType = header.GetField(Fields.Tags.MsgType);
                string beginString = header.GetField(Fields.Tags.BeginString);

                if (!beginString.Equals(this.SessionID.BeginString))
                    throw new UnsupportedVersion();

                if (MsgType.LOGON.Equals(msgType))
                {
                    if (this.SessionID.IsFIXT)
                    {
                        targetDefaultApplVerID = new ApplVerID(message.GetString(Fields.Tags.DefaultApplVerID));
                    }
                    else
                    {
                        targetDefaultApplVerID = Message.GetApplVerID(beginString);
                    }
                }

                if (this.SessionID.IsFIXT && !Message.IsAdminMsgType(msgType))
                {
                    DataDictionary.DataDictionary.Validate(message, SessionDataDictionary, ApplicationDataDictionary, beginString, msgType);
                }
                else
                {
                    this.SessionDataDictionary.Validate(message, beginString, msgType);
                }

                //End Refactor
                if (MsgType.LOGON.Equals(msgType))
                    NextLogon(message);
                else if (MsgType.HEARTBEAT.Equals(msgType))
                    NextHeartbeat(message);
                else if (MsgType.TEST_REQUEST.Equals(msgType))
                    NextTestRequest(message);
                else if (MsgType.SEQUENCE_RESET.Equals(msgType))
                    NextSequenceReset(message);
                else if (MsgType.LOGOUT.Equals(msgType))
                    NextLogout(message);
                else if (MsgType.RESEND_REQUEST.Equals(msgType))
                    NextResendRequest(message);
                else
                {
                    if (!Verify(message))
                        return;
                    state_.IncrNextTargetMsgSeqNum();
                }
            }
            catch (TagException e)
            {
                if (null != e.InnerException)
                    this.Log.OnEvent(e.InnerException.Message);
                GenerateReject(message, e.sessionRejectReason, e.field);
            }
            catch (UnsupportedVersion)
            {
                if (MsgType.LOGOUT.Equals(msgType))
                {
                    NextLogout(message);
                }
                else
                {
                    GenerateLogout("Incorrect BeginString");
                    state_.IncrNextTargetMsgSeqNum();
                }
            }
            catch (UnsupportedMessageType e)
            {
                this.Log.OnEvent("Unsupported message type: " + e.Message);
                GenerateBusinessMessageReject(message, Fields.BusinessRejectReason.UNKNOWN_MESSAGE_TYPE, 0);
            }
            catch (FieldNotFoundException e)
            {
                this.Log.OnEvent("Rejecting invalid message, field not found: " + e.Message);
                if ((SessionID.BeginString.CompareTo(FixValues.BeginString.FIX42) >= 0) && (message.IsApp()))
                {
                    GenerateBusinessMessageReject(message, Fields.BusinessRejectReason.CONDITIONALLY_REQUIRED_FIELD_MISSING, e.Field);
                }
                else
                {
                    if (msgType.Equals(Fields.MsgType.LOGON))
                    {
                        this.Log.OnEvent("Required field missing from logon");
                        Disconnect("Required field missing from logon");
                    }
                    else
                        GenerateReject(message, new QuickFix.FixValues.SessionRejectReason(SessionRejectReason.REQUIRED_TAG_MISSING, "Required Tag Missing"), e.Field);
                }
            }
            catch (RejectLogon e)
            {
                GenerateLogout(e.Message);
                Disconnect(e.ToString());
            }

            NextQueued();
            Next();
        }
Beispiel #4
0
        public static QuickFix.FIX44.OrderCancelReject Fix44Reject2OrderCancelReject(QuickFix.Message msgReject, QuickFix.Message msgOri)
        {
            try
            {
                QuickFix.FIX44.OrderCancelReject ocr = new QuickFix.FIX44.OrderCancelReject();
                if (msgOri.IsSetField(Tags.OrderID))
                {
                    ocr.Set(new OrderID(msgOri.GetString(Tags.OrderID)));
                }
                else
                {
                    ocr.Set(new OrderID("NONE"));
                }
                ocr.Set(new ClOrdID(msgOri.GetString(Tags.ClOrdID)));           // mandatory
                ocr.Set(new OrigClOrdID(msgOri.GetString(Tags.OrigClOrdID)));   // mandatory
                ocr.Set(new OrdStatus(OrdStatus.REJECTED));                     // mandatory
                if (msgOri.IsSetField(Tags.Account))
                {
                    ocr.SetField(new Account(msgOri.GetString(Tags.Account)));
                }
                if (msgOri.Header.GetString(Tags.MsgType).Equals(MsgType.ORDER_CANCEL_REQUEST)) // mandatory
                {
                    ocr.Set(new CxlRejResponseTo('1'));
                }
                else
                {
                    ocr.Set(new CxlRejResponseTo('2'));
                }
                if (msgReject.IsSetField(Tags.Text))
                {
                    ocr.Set(new Text(msgReject.GetString(Tags.Text)));
                }
                // ocr.Set(new CxlRejReason(2137));

                // Tratamento tag SecondaryOrderID
                // Se nao vier na mensagem busca pelo TO
                //if (msgOri.IsSetField(Tags.SecondaryOrderID))
                //{
                //    ocr.Set(new SecondaryOrderID(msgOri.GetString(Tags.SecondaryOrderID)));
                //}
                //else
                //{
                //    if (null != to)
                //    {
                //        if (!string.IsNullOrEmpty(to.SecondaryOrderID))
                //            ocr.Set(new SecondaryOrderID(to.SecondaryOrderID));
                //
                //        if (!string.IsNullOrEmpty(to.TradeDate))
                //            ocr.Set(new TradeDate(to.TradeDate));
                //    }
                //}
                int len = msgOri.GetInt(Tags.NoPartyIDs);
                for (int i = 0; i < len; i++)
                {
                    Group grp = msgOri.GetGroup(i + 1, Tags.NoPartyIDs);
                    ocr.AddGroup(grp);
                }
                ocr.Set(new Symbol(msgOri.GetString(Tags.Symbol)));
                if (msgOri.IsSetField(Tags.SecurityID))
                {
                    ocr.Set(new SecurityID(msgOri.GetField(Tags.SecurityID)));
                }
                if (msgOri.IsSetField(Tags.SecurityIDSource))
                {
                    ocr.Set(new SecurityIDSource(msgOri.GetField(Tags.SecurityIDSource)));
                }
                ocr.Set(new Side(msgOri.GetChar(Tags.Side)));
                if (msgOri.IsSetField(Tags.Memo))
                {
                    ocr.Set(new Memo(msgOri.GetString(Tags.Memo)));
                }
                return(ocr);
            }
            catch (Exception ex)
            {
                logger.Error("Fix44Reject2OrderCancelReject(): " + ex.Message, ex);
                return(null);
            }
        }
Beispiel #5
0
        public static QuickFix.FIX44.ExecutionReport Fix44Rejection2ExecutionReport(QuickFix.Message msgReject, QuickFix.Message msgOri)
        {
            try
            {
                QuickFix.FIX44.ExecutionReport er = new QuickFix.FIX44.ExecutionReport();
                if (msgOri.IsSetField(Tags.OrderID))
                {
                    er.Set(new OrderID(msgOri.GetString(Tags.OrderID)));
                }
                else
                {
                    er.Set(new OrderID("NONE"));
                }

                if (msgOri.IsSetField(Tags.ClOrdID))
                {
                    er.Set(new ClOrdID(msgOri.GetField(Tags.ClOrdID)));
                }
                if (msgOri.IsSetField(Tags.OrigClOrdID))
                {
                    er.Set(new OrigClOrdID(msgOri.GetField(Tags.OrigClOrdID)));
                }
                // Fazer atribuicao dos PartyIDs da mensagem original
                int len = msgOri.GetInt(Tags.NoPartyIDs);
                for (int i = 0; i < len; i++)
                {
                    Group grp = msgOri.GetGroup(i + 1, Tags.NoPartyIDs);
                    er.AddGroup(grp);
                }
                er.Set(new ExecID(DateTime.Now.ToString("yyyyMMddHHmmssfff")));
                er.Set(new ExecType(ExecType.REJECTED));
                er.Set(new OrdStatus(OrdStatus.REJECTED));
                if (msgOri.IsSetField(Tags.Account))
                {
                    er.Set(new Account(msgOri.GetField(Tags.Account)));
                }
                er.Set(new Symbol(msgOri.GetField(Tags.Symbol)));
                if (msgOri.IsSetField(Tags.SecurityID))
                {
                    er.Set(new SecurityID(msgOri.GetField(Tags.SecurityID)));
                }
                if (msgOri.IsSetField(Tags.SecurityIDSource))
                {
                    er.Set(new SecurityIDSource(msgOri.GetField(Tags.SecurityIDSource)));
                }
                er.Set(new Side(msgOri.GetChar(Tags.Side)));
                er.Set(new OrderQty(msgOri.GetDecimal(Tags.OrderQty)));
                if (msgOri.IsSetField(Tags.OrdType))
                {
                    er.Set(new OrdType(msgOri.GetChar(Tags.OrdType)));
                }
                if (msgOri.IsSetField(Tags.Price))
                {
                    er.Set(new Price(msgOri.GetDecimal(Tags.Price)));
                }
                if (msgOri.IsSetField(Tags.StopPx))
                {
                    er.Set(new StopPx(msgOri.GetDecimal(Tags.StopPx)));
                }
                if (msgOri.IsSetField(Tags.TimeInForce))
                {
                    er.Set(new TimeInForce(msgOri.GetChar(Tags.TimeInForce)));
                }
                if (msgOri.IsSetField(Tags.ExpireDate))
                {
                    er.Set(new ExpireDate(msgOri.GetField(Tags.ExpireDate)));
                }
                er.Set(new LeavesQty(0));
                er.Set(new CumQty(0));
                er.Set(new AvgPx(Decimal.Zero));
                DateTime transact = DateTime.UtcNow;
                er.Set(new TransactTime(transact));
                if (msgOri.IsSetField(Tags.MaxFloor))
                {
                    er.Set(new MaxFloor(msgOri.GetDecimal(Tags.MaxFloor)));
                }
                if (msgOri.IsSetField(Tags.Memo))
                {
                    er.SetField(new Memo(msgOri.GetString(Tags.Memo)));
                }

                if (msgReject.IsSetField(Tags.Text))
                {
                    er.Set(new Text(msgReject.GetField(Tags.Text)));
                }
                if (msgReject.IsSetField(Tags.OrderID))
                {
                    er.Set(new OrderID(msgReject.GetField(Tags.OrderID)));
                }

                return(er);
            }
            catch (Exception ex)
            {
                logger.Error("Fix44Rejection2ExecutionReport(): " + ex.Message, ex);
                return(null);
            }
        }
Beispiel #6
0
        public static QuickFix.FIX42.OrderCancelReject Fix42Reject2OrderCancelReject(QuickFix.Message msgReject, QuickFix.Message msgOri)
        {
            try
            {
                QuickFix.FIX42.OrderCancelReject ocr = new QuickFix.FIX42.OrderCancelReject();

                if (msgOri.IsSetField(Tags.OrderID))
                {
                    ocr.Set(new OrderID(msgOri.GetString(Tags.OrderID)));
                }
                else
                {
                    ocr.Set(new OrderID("NONE"));
                }
                if (msgOri.IsSetField(Tags.SecondaryOrderID))
                {
                    ocr.Set(new SecondaryOrderID(msgOri.GetString(Tags.SecondaryOrderID)));
                }
                if (msgOri.IsSetField(Tags.ClOrdID))
                {
                    ocr.Set(new ClOrdID(msgOri.GetString(Tags.ClOrdID)));
                }
                if (msgOri.IsSetField(Tags.OrigClOrdID))
                {
                    ocr.Set(new OrigClOrdID(msgOri.GetString(Tags.OrigClOrdID)));
                }
                ocr.Set(new OrdStatus(OrdStatus.REJECTED));
                // if (msgOri.IsSetField(Tags.ClientID)) ocr.Set(new ClientID(msgOri.GetString(Tags.ClientID))); // not found on 4.4EP
                // TODO[FF] - Verificar a montagem do execbroker a partir de party ids
                // if (msgOri.IsSetField(Tags.ExecBroker)) ocr.Set(new ExecBroker(msgOri.GetString(Tags.ExecBroker))); // not found on 4.4EP
                if (msgOri.IsSetField(Tags.ListID))
                {
                    ocr.Set(new ListID(msgOri.GetString(Tags.ListID)));
                }
                if (msgOri.IsSetField(Tags.Account))
                {
                    ocr.Set(new Account(msgOri.GetString(Tags.Account)));
                }
                if (msgOri.IsSetField(Tags.TransactTime))
                {
                    ocr.Set(new TransactTime(msgOri.GetDateTime(Tags.TransactTime)));
                }
                if (msgOri.Header.GetString(Tags.MsgType).Equals(MsgType.ORDER_CANCEL_REQUEST)) // mandatory
                {
                    ocr.Set(new CxlRejResponseTo('1'));
                }
                else
                {
                    ocr.Set(new CxlRejResponseTo('2'));
                }
                //if (msgOri.IsSetField(Tags.CxlRejReason)) ocr.Set(new CxlRejReason(msgOri.GetInt(Tags.CxlRejReason)));
                if (msgOri.IsSetField(Tags.CxlRejReason))
                {
                    ocr.Set(new CxlRejReason(CxlRejReason.BROKER_OPTION));
                }
                if (msgOri.IsSetField(Tags.Text))
                {
                    ocr.Set(new Text(msgOri.GetString(Tags.Text)));
                }
                if (msgOri.IsSetField(Tags.EncodedTextLen))
                {
                    ocr.Set(new EncodedTextLen(msgOri.GetInt(Tags.EncodedTextLen)));
                }
                if (msgOri.IsSetField(Tags.EncodedText))
                {
                    ocr.Set(new EncodedText(msgOri.GetString(Tags.EncodedText)));
                }
                if (msgOri.IsSetField(Tags.Memo))
                {
                    ocr.SetField(new Memo(msgOri.GetString(Tags.Memo)));
                }

                /*
                 * if (msgOri.IsSetField(Tags.OrderID))
                 *  ocr.Set(new OrderID(msgOri.GetString(Tags.OrderID)));
                 * else
                 *  ocr.Set(new OrderID("NONE"));
                 * ocr.Set(new ClOrdID(msgOri.GetString(Tags.ClOrdID)));           // mandatory
                 * ocr.Set(new OrigClOrdID(msgOri.GetString(Tags.OrigClOrdID)));   // mandatory
                 * ocr.Set(new OrdStatus(OrdStatus.REJECTED));                     // mandatory
                 * if (msgOri.IsSetField(Tags.Account))
                 *  ocr.SetField(new Account(msgOri.GetString(Tags.Account)));
                 * if (msgOri.Header.GetString(Tags.MsgType).Equals(MsgType.ORDER_CANCEL_REQUEST)) // mandatory
                 *  ocr.Set(new CxlRejResponseTo('1'));
                 * else
                 *  ocr.Set(new CxlRejResponseTo('2'));
                 * if (msgReject.IsSetField(Tags.Text))
                 *  ocr.Set(new Text(msgReject.GetString(Tags.Text)));
                 * int len = msgOri.GetInt(Tags.NoPartyIDs);
                 * for (int i = 0; i < len; i++)
                 * {
                 *  Group grp = msgOri.GetGroup(i + 1, Tags.NoPartyIDs);
                 *  ocr.AddGroup(grp);
                 * }
                 * ocr.SetField(new Symbol(msgOri.GetString(Tags.Symbol)));
                 * if (msgOri.IsSetField(Tags.SecurityID)) ocr.SetField(new SecurityID(msgOri.GetField(Tags.SecurityID)));
                 * if (msgOri.IsSetField(Tags.SecurityIDSource)) ocr.SetField(new SecurityIDSource(msgOri.GetField(Tags.SecurityIDSource)));
                 * ocr.SetField(new Side(msgOri.GetChar(Tags.Side)));
                 * if (msgOri.IsSetField(Tags.Memo))
                 *  ocr.SetField(new Memo(msgOri.GetString(Tags.Memo)));
                 */
                return(ocr);
            }
            catch (Exception ex)
            {
                logger.Error("Fix42Reject2OrderCancelReject(): " + ex.Message, ex);
                return(null);
            }
        }