Exemplo n.º 1
0
        public bool GenerateHeartbeat(Message testRequest)
        {
            Message heartbeat = msgFactory_.Create(this.SessionID.BeginString, Fields.MsgType.HEARTBEAT);

            InitializeHeader(heartbeat);
            try
            {
                heartbeat.SetField(new Fields.TestReqID(testRequest.GetField(Fields.Tags.TestReqID)));
            }
            catch (FieldNotFoundException)
            { }
            return(SendRaw(heartbeat, 0));
        }
Exemplo n.º 2
0
        protected void NextLogon(Message logon)
        {
            Fields.ResetSeqNumFlag resetSeqNumFlag = new Fields.ResetSeqNumFlag(false);
            if (logon.IsSetField(resetSeqNumFlag))
            {
                logon.GetField(resetSeqNumFlag);
            }
            state_.ReceivedReset = resetSeqNumFlag.Obj;

            if (!state_.IsInitiator && this.ResetOnLogon)
            {
                state_.Reset();
            }

            if (!Verify(logon, false, true))
            {
                return;
            }

            if (!IsGoodTime(logon))
            {
                this.Log.OnEvent("Logon had bad sending time");
                Disconnect("bad sending time");
                return;
            }

            state_.ReceivedLogon = true;
            this.Log.OnEvent("Received logon");
            if (!state_.IsInitiator)
            {
                int heartBtInt = logon.GetInt(Fields.Tags.HeartBtInt);
                state_.HeartBtInt = heartBtInt;
                GenerateLogon(heartBtInt);
                this.Log.OnEvent("Responding to logon request");
            }

            state_.SentReset     = false;
            state_.ReceivedReset = false;

            int msgSeqNum = logon.Header.GetInt(Fields.Tags.MsgSeqNum);

            if (IsTargetTooHigh(msgSeqNum) && !resetSeqNumFlag.Obj)
            {
                DoTargetTooHigh(logon, msgSeqNum);
            }
            else
            {
                state_.IncrNextTargetMsgSeqNum();
                NextQueued();
            }
        }
Exemplo n.º 3
0
        protected bool SendRaw(Message message, int seqNum)
        {
            lock (sync_)
            {
                string msgType = message.Header.GetField(Fields.Tags.MsgType);

                InitializeHeader(message, seqNum);

                if (Message.IsAdminMsgType(msgType))
                {
                    /// FIXME this.Application.ToAdmin(message, this.SessionID);

                    if (MsgType.LOGON.Equals(msgType) && !state_.ReceivedReset)
                    {
                        Fields.ResetSeqNumFlag resetSeqNumFlag = new QuickFix.Fields.ResetSeqNumFlag(false);
                        if (message.IsSetField(resetSeqNumFlag))
                        {
                            message.GetField(resetSeqNumFlag);
                        }
                        if (resetSeqNumFlag.getValue())
                        {
                            state_.Reset();
                            message.Header.SetField(new Fields.MsgSeqNum(state_.GetNextSenderMsgSeqNum()));
                        }
                        state_.SentReset = resetSeqNumFlag.Obj;
                    }
                }

                string messageString = message.ToString();
                if (0 == seqNum)
                {
                    Persist(message, messageString);
                }
                return(Send(messageString));
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// FIXME totally bogus
 /// </summary>
 /// <param name="msg"></param>
 /// <returns></returns>
 public static string GetMsgType(string msg)
 {
     Message FIXME = new Message(msg);
     return FIXME.GetField(Tags.MsgType);
 }
Exemplo n.º 5
0
        public void SetFieldsTest()
        {
            var message = new Message();
            var allocId = new AllocID("123456");
            var allocAccount = new AllocAccount("QuickFixAccount");
            var allocAccountType = new AllocAccountType(AllocAccountType.HOUSE_TRADER);
            message.SetFields(new IField[] { allocAccount, allocAccountType, allocId });

            Assert.AreEqual(true, message.IsSetField(Tags.AllocID));
            Assert.AreEqual("123456", message.GetField(Tags.AllocID));

            Assert.AreEqual(true, message.IsSetField(Tags.AllocAccount));
            Assert.AreEqual("QuickFixAccount", message.GetField(Tags.AllocAccount));

            Assert.AreEqual(true, message.IsSetField(Tags.AllocAccountType));
            Assert.AreEqual(AllocAccountType.HOUSE_TRADER, message.GetInt(Tags.AllocAccountType));
        }
Exemplo n.º 6
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"));
 }
Exemplo n.º 7
0
        protected void NextLogon(Message logon)
        {
            Fields.ResetSeqNumFlag resetSeqNumFlag = new Fields.ResetSeqNumFlag(false);
            if (logon.IsSetField(resetSeqNumFlag))
                logon.GetField(resetSeqNumFlag);
            state_.ReceivedReset = resetSeqNumFlag.Obj;

            if (state_.ReceivedReset)
            {
                this.Log.OnEvent("Sequence numbers reset due to ResetSeqNumFlag=Y");
                if (!state_.SentReset)
                {
                    state_.Reset("Reset requested by counterparty");
                }
            }

            if (!state_.IsInitiator && this.ResetOnLogon)
                state_.Reset("ResetOnLogon");
            if (this.RefreshOnLogon)
                Refresh();

            if (!Verify(logon, false, true))
                return;

            if (!IsGoodTime(logon))
            {
                this.Log.OnEvent("Logon has bad sending time");
                Disconnect("bad sending time");
                return;
            }

            state_.ReceivedLogon = true;
            this.Log.OnEvent("Received logon");
            if (!state_.IsInitiator)
            {
                int heartBtInt = logon.GetInt(Fields.Tags.HeartBtInt);
                state_.HeartBtInt = (int)Math.Floor(heartBtInt / (double)2);
                GenerateLogon(logon);
                this.Log.OnEvent("Responding to logon request");
            }

            state_.SentReset = false;
            state_.ReceivedReset = false;

            int msgSeqNum = logon.Header.GetInt(Fields.Tags.MsgSeqNum);
            if (IsTargetTooHigh(msgSeqNum) && !resetSeqNumFlag.Obj)
            {
                DoTargetTooHigh(logon, msgSeqNum);
            }
            else
            {
                state_.IncrNextTargetMsgSeqNum();
            }

            if (this.IsLoggedOn)
                this.Application.OnLogon(this.SessionID);
        }
Exemplo n.º 8
0
        protected bool SendRaw(Message message, int seqNum)
        {
            
            lock (sync_)
            {
                string msgType = message.Header.GetField(Fields.Tags.MsgType);
                if (msgType == Fields.MsgType.HEARTBEAT)
                {
                    _log.Info("Sending heartbeat inside sendraw");
                }

                InitializeHeader(message, seqNum);

                if (Message.IsAdminMsgType(msgType))
                {
                    this.Application.ToAdmin(message, this.SessionID);

                    if (MsgType.LOGON.Equals(msgType) && !state_.ReceivedReset)
                    {
                        Fields.ResetSeqNumFlag resetSeqNumFlag = new QuickFix.Fields.ResetSeqNumFlag(false);
                        if (message.IsSetField(resetSeqNumFlag))
                            message.GetField(resetSeqNumFlag);
                        if (resetSeqNumFlag.getValue())
                        {
                            state_.Reset("ResetSeqNumFlag");
                            message.Header.SetField(new Fields.MsgSeqNum(state_.GetNextSenderMsgSeqNum()));
                        }
                        state_.SentReset = resetSeqNumFlag.Obj;
                    }
                }
                else
                {
                    try
                    {
                        this.Application.ToApp(message, this.SessionID);
                    }
                    catch (DoNotSend)
                    {
                        return false;
                    }
                }

                string messageString = message.ToString();
                if (0 == seqNum)
                    Persist(message, messageString);
                
                if (msgType == Fields.MsgType.HEARTBEAT)
                {
                    _log.Info("about to send that heartbeat for real");
                }

                return Send(messageString, msgType == Fields.MsgType.HEARTBEAT);
            }
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
        protected bool SendRaw(Message message, int seqNum)
        {
            lock (sync_)
            {
                string msgType = message.Header.GetField(Fields.Tags.MsgType);

                InitializeHeader(message, seqNum);

                if (Message.IsAdminMsgType(msgType))
                {
                    this.Application.ToAdmin(message, this.SessionID);

                    if (MsgType.LOGON.Equals(msgType) && !state_.ReceivedReset)
                    {
                        Fields.ResetSeqNumFlag resetSeqNumFlag = new QuickFix.Fields.ResetSeqNumFlag(false);
                        if (message.IsSetField(resetSeqNumFlag))
                            message.GetField(resetSeqNumFlag);
                        if (resetSeqNumFlag.getValue())
                        {
                            state_.Reset();
                            message.Header.SetField(new Fields.MsgSeqNum(state_.GetNextSenderMsgSeqNum()));
                        }
                        state_.SentReset = resetSeqNumFlag.Obj;
                    }
                }
                else
                {
                    this.Application.ToApp(message, this.SessionID);
                }

                string messageString = message.ToString();
                if (0 == seqNum)
                    Persist(message, messageString);
                return Send(messageString);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// FIXME totally bogus
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static string GetMsgType(string msg)
        {
            Message FIXME = new Message(msg);

            return(FIXME.GetField(Tags.MsgType));
        }
Exemplo n.º 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));
                }
            }

        }
Exemplo n.º 13
0
        public void TestMessageParserIntegrity()
        {
            string fix = "5=ASDF" + Message.SOH + "10=234" + Message.SOH;

            Message m = new Message();
            StringField sf = new StringField(0);

            MakeMessage(m, fix);

            Assert.That(m.GetField(5), Is.EqualTo("ASDF"));
            Assert.That(m.GetField(10), Is.EqualTo("234"));
        }
Exemplo n.º 14
0
        public static List <QuickFix.FIX44.ExecutionReport> Fix44Rejection2ExecutionReportNOC(QuickFix.Message msgReject, QuickFix.FIX44.NewOrderCross noc)
        {
            try
            {
                QuickFix.FIX44.ExecutionReport er1 = new QuickFix.FIX44.ExecutionReport();
                QuickFix.FIX44.ExecutionReport er2 = new QuickFix.FIX44.ExecutionReport();
                er1.Set(new OrderID("NONE"));
                er2.Set(new OrderID("NONE"));
                if (noc.IsSetNoSides() && noc.NoSides.getValue() == 2)
                {
                    QuickFix.Group grpNoSides = noc.GetGroup(1, Tags.NoSides);
                    if (grpNoSides.IsSetField(Tags.ClOrdID))
                    {
                        er1.Set(new ClOrdID(grpNoSides.GetField(Tags.ClOrdID)));
                    }
                    er1.Set(new ExecID(DateTime.Now.ToString("yyyyMMddHHmmssfff")));
                    er1.Set(new ExecType(ExecType.REJECTED));
                    er1.Set(new OrdStatus(OrdStatus.REJECTED));
                    if (grpNoSides.IsSetField(Tags.Account))
                    {
                        er1.Set(new Account(grpNoSides.GetField(Tags.Account)));
                    }
                    er1.Set(new Symbol(noc.GetField(Tags.Symbol)));
                    if (noc.IsSetField(Tags.SecurityID))
                    {
                        er1.Set(new SecurityID(noc.GetField(Tags.SecurityID)));
                    }
                    if (noc.IsSetField(Tags.SecurityIDSource))
                    {
                        er1.Set(new SecurityIDSource(noc.GetField(Tags.SecurityIDSource)));
                    }
                    er1.Set(new Side(grpNoSides.GetChar(Tags.Side)));
                    er1.Set(new OrderQty(grpNoSides.GetDecimal(Tags.OrderQty)));
                    if (noc.IsSetField(Tags.OrdType))
                    {
                        er1.Set(new OrdType(noc.GetChar(Tags.OrdType)));
                    }
                    if (noc.IsSetField(Tags.Price))
                    {
                        er1.Set(new Price(noc.GetDecimal(Tags.Price)));
                    }
                    er1.Set(new LeavesQty(0));
                    er1.Set(new CumQty(0));
                    er1.Set(new AvgPx(Decimal.Zero));
                    DateTime transact1 = DateTime.UtcNow;
                    er1.Set(new TransactTime(transact1));
                    if (msgReject.IsSetField(Tags.Text))
                    {
                        er1.Set(new Text(msgReject.GetField(Tags.Text)));
                    }

                    grpNoSides = noc.GetGroup(2, Tags.NoSides);
                    if (grpNoSides.IsSetField(Tags.ClOrdID))
                    {
                        er2.Set(new ClOrdID(grpNoSides.GetField(Tags.ClOrdID)));
                    }
                    er2.Set(new ExecID(DateTime.Now.ToString("yyyyMMddHHmmssfff")));
                    er2.Set(new ExecType(ExecType.REJECTED));
                    er2.Set(new OrdStatus(OrdStatus.REJECTED));
                    if (grpNoSides.IsSetField(Tags.Account))
                    {
                        er2.Set(new Account(grpNoSides.GetField(Tags.Account)));
                    }
                    er2.Set(new Symbol(noc.GetField(Tags.Symbol)));
                    if (noc.IsSetField(Tags.SecurityID))
                    {
                        er2.Set(new SecurityID(noc.GetField(Tags.SecurityID)));
                    }
                    if (noc.IsSetField(Tags.SecurityIDSource))
                    {
                        er2.Set(new SecurityIDSource(noc.GetField(Tags.SecurityIDSource)));
                    }
                    er2.Set(new Side(grpNoSides.GetChar(Tags.Side)));
                    er2.Set(new OrderQty(grpNoSides.GetDecimal(Tags.OrderQty)));
                    if (noc.IsSetField(Tags.OrdType))
                    {
                        er2.Set(new OrdType(noc.GetChar(Tags.OrdType)));
                    }
                    if (noc.IsSetField(Tags.Price))
                    {
                        er2.Set(new Price(noc.GetDecimal(Tags.Price)));
                    }
                    er2.Set(new LeavesQty(0));
                    er2.Set(new CumQty(0));
                    er2.Set(new AvgPx(Decimal.Zero));
                    DateTime transact2 = DateTime.UtcNow;
                    er2.Set(new TransactTime(transact2));
                    if (msgReject.IsSetField(Tags.Text))
                    {
                        er2.Set(new Text(msgReject.GetField(Tags.Text)));
                    }
                }

                List <QuickFix.FIX44.ExecutionReport> ret = new List <QuickFix.FIX44.ExecutionReport>();
                ret.Add(er1);
                ret.Add(er2);
                return(ret);
            }
            catch (Exception ex)
            {
                logger.Error("Fix44Rejection2ExecutionReportNOC(): " + ex.Message, ex);
                return(null);
            }
        }
Exemplo n.º 15
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);
            }
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
        protected void NextLogon(Message logon)
        {
            Fields.ResetSeqNumFlag resetSeqNumFlag = new Fields.ResetSeqNumFlag(false);
            if (logon.IsSetField(resetSeqNumFlag))
                logon.GetField(resetSeqNumFlag);
            state_.ReceivedReset = resetSeqNumFlag.Obj;

            if (!state_.IsInitiator && this.ResetOnLogon)
                state_.Reset();

            if (!Verify(logon, false, true))
                return;

            if (!IsGoodTime(logon))
            {
                this.Log.OnEvent("Logon had bad sending time");
                Disconnect("bad sending time");
                return;
            }

            state_.ReceivedLogon = true;
            this.Log.OnEvent("Received logon");
            if (!state_.IsInitiator)
            {
                int heartBtInt = logon.GetInt(Fields.Tags.HeartBtInt);
                state_.HeartBtInt = heartBtInt;
                GenerateLogon(logon);
                this.Log.OnEvent("Responding to logon request");
            }

            state_.SentReset = false;
            state_.ReceivedReset = false;

            int msgSeqNum = logon.Header.GetInt(Fields.Tags.MsgSeqNum);
            if (IsTargetTooHigh(msgSeqNum) && !resetSeqNumFlag.Obj)
            {
                DoTargetTooHigh(logon, msgSeqNum);
            }
            else
            {
                state_.IncrNextTargetMsgSeqNum();
                NextQueued();
            }

            if (this.IsLoggedOn)
                this.Application.OnLogon(this.SessionID);
        }
Exemplo n.º 18
0
        private void _processMessage(TOMessage to)
        {
            try
            {
                if (null != to)
                {
                    QuickFix.Message msgQF   = to.MensagemQF;
                    string           msgType = msgQF.Header.GetField(Tags.MsgType);
                    int    account           = 0;
                    string strAcc            = string.Empty;
                    #region Limit Validation
                    // Atualizacao dos valores de limite, de acordo com o execution report
                    if (this.CalcularLimite)
                    {
                        if (this.Config.Bolsa.Equals(ExchangePrefixes.BOVESPA, StringComparison.InvariantCultureIgnoreCase))
                        {
                            strAcc = msgQF.IsSetField(Tags.Account) ? msgQF.GetField(Tags.Account) : string.Empty;
                            if (!string.IsNullOrEmpty(strAcc))
                            {
                                account = Convert.ToInt32(strAcc.Remove(strAcc.Length - 1));
                            }
                            else
                            {
                                account = 0;
                            }
                        }
                        else
                        {
                            strAcc = msgQF.IsSetField(Tags.Account) ? msgQF.GetField(Tags.Account) : string.Empty;
                            if (!string.IsNullOrEmpty(strAcc))
                            {
                                account = Convert.ToInt32(strAcc);
                            }
                            else
                            {
                                account = 0;
                            }
                        }
                        bool          bProfileInst = false;
                        LimitResponse retProfile   = LimiteManager.LimitControl.GetInstance().VerifyInstitutionalProfile(account);

                        if (0 != retProfile.ErrorCode)
                        {
                            bProfileInst = true;
                        }
                        if (msgType == MsgType.EXECUTION_REPORT && !bProfileInst)
                        {
                            // Validar o perfil instituicional

                            QuickFix.FIX44.ExecutionReport er = (QuickFix.FIX44.ExecutionReport)msgQF;
                            // Bovespa
                            if (this.Config.Bolsa.Equals(ExchangePrefixes.BOVESPA, StringComparison.InvariantCultureIgnoreCase))
                            {
                                // BOVESPA
                                decimal ultimoPreco = StreamerManager.GetInstance().GetLastPrice(er.Symbol.ToString());
                                if (Decimal.Zero != ultimoPreco)
                                {
                                    LimitResponse ret          = new LimitResponse();
                                    decimal       valorAlocado = er.OrderQty.getValue() * ultimoPreco;
                                    // Retirar o digito verificador

                                    string chaveAtual = er.ClOrdID.ToString() + "-" + strAcc + "-" + er.Symbol.ToString();

                                    switch (er.OrdStatus.getValue())
                                    {
                                    // Alocar limite da parte e contra parte
                                    case OrdStatus.NEW:
                                    case OrdStatus.REPLACED:
                                    case OrdStatus.CANCELED:
                                    {
                                        // Buscar o "new order" referencial para busca do TipoLimite
                                        // toOrder = this.Initiator.GetTOOrderSession(chaveAtual);
                                        if (null == to.Order)
                                        {
                                            logger.Info("RefOrder não encontrada (New): " + chaveAtual);
                                        }
                                        else
                                        {
                                            ret = LimiteManager.LimitControl.GetInstance().UpdateOperationalLimitBovespa(account, to.TipoLimite, valorAlocado, ultimoPreco, Convert.ToInt32(er.Side.ToString()), er.OrdStatus.getValue());
                                            if (0 != ret.ErrorCode)
                                            {
                                                logger.Info("Erro na atualizacao do limite operacional Bovespa (New): " + ret.ErrorMessage);
                                            }
                                        }
                                    }
                                    break;

                                    // Atualizar a quantidade executada
                                    case OrdStatus.FILLED:
                                    case OrdStatus.PARTIALLY_FILLED:
                                        if (null != to.Order)
                                        {
                                            to.Order.CumQty = Convert.ToInt32(er.CumQty.getValue());
                                            valorAlocado    = er.CumQty.getValue() * ultimoPreco;
                                            ret             = LimiteManager.LimitControl.GetInstance().UpdateOperationalLimitBovespa(account, to.TipoLimite, valorAlocado, ultimoPreco, Convert.ToInt32(er.Side.ToString()), er.OrdStatus.getValue());
                                            if (0 != ret.ErrorCode)
                                            {
                                                logger.Info("Erro na atualizacao do limite operacional Bovespa (Filled / Partially Filled): " + ret.ErrorMessage);
                                            }
                                        }
                                        else
                                        {
                                            logger.Info("RefOrder não encontrada (New): " + chaveAtual);
                                        }
                                        break;
                                    }
                                }
                                else
                                {
                                    string symbol = er.IsSetSymbol() ? er.Symbol.getValue() : string.Empty;
                                    logger.Info("Preco base (ultimo preco) zerado, ignorando o calculo do limite: " + symbol);
                                }
                            }
                            //bmf
                            else
                            {
                                // BMF
                                // account = er.IsSetField(Tags.Account)?  Convert.ToInt32(er.Account.getValue()): 0;
                                LimitResponse ret  = null;
                                string        side = er.Side.getValue() == '1' ? "C" : "V";
                                switch (er.OrdStatus.getValue())
                                {
                                case OrdStatus.NEW:
                                    ret = LimiteManager.LimitControl.GetInstance()
                                          .UpdateOperationalLimitBMF(Convert.ToInt32(er.Account.getValue()), to.TipoLimite,
                                                                     er.Symbol.getValue(), Convert.ToInt32(er.OrderQty.getValue()), 0, side);
                                    break;

                                case OrdStatus.REPLACED:
                                {
                                    int qtdResult = (-1) * (to.Order.OrderQty - to.Order.CumQty);
                                    ret = LimiteManager.LimitControl.GetInstance()
                                          .UpdateOperationalLimitBMF(Convert.ToInt32(er.Account.getValue()), to.TipoLimite,
                                                                     er.Symbol.getValue(), qtdResult, Convert.ToInt32(er.OrderQty.getValue()), side);
                                }
                                break;

                                case OrdStatus.CANCELED:
                                {
                                    int qtdResult = (-1) * (to.Order.OrderQty - to.Order.CumQty);
                                    ret = LimiteManager.LimitControl.GetInstance()
                                          .UpdateOperationalLimitBMF(Convert.ToInt32(er.Account.getValue()), to.TipoLimite,
                                                                     er.Symbol.getValue(), qtdResult, 0, side);
                                }
                                break;

                                // Atualizando a quantidade de
                                case OrdStatus.FILLED:
                                case OrdStatus.PARTIALLY_FILLED:
                                    if (null != to.Order)
                                    {
                                        to.Order.CumQty = Convert.ToInt32(er.CumQty.getValue());
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    #endregion

                    // Efetuar verificacao da integracao utilizada, para efetuar a conversao do
                    switch (this.Config.IntegrationID)
                    {
                    case IntegrationId.BBG:
                        this._sendMessageBBGIntegration(msgType, msgQF, to, account);
                        break;

                    case IntegrationId.GRD:
                    case IntegrationId.IVF:
                    default:
                        this._sendDefaultMessageIntegration(msgQF, to, account);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("_processMessage(): " + ex.Message, ex);
            }
        }
Exemplo n.º 19
0
 public bool GenerateHeartbeat(Message testRequest)
 {
     Message heartbeat = msgFactory_.Create(this.SessionID.BeginString, Fields.MsgType.HEARTBEAT);
     InitializeHeader(heartbeat);
     try
     {
         heartbeat.SetField(new Fields.TestReqID(testRequest.GetField(Fields.Tags.TestReqID)));
         if (this.EnableLastMsgSeqNumProcessed)
         {
             heartbeat.Header.SetField(new Fields.LastMsgSeqNumProcessed(testRequest.Header.GetInt(Tags.MsgSeqNum)));
         }
     }
     catch (FieldNotFoundException)
     { }
     return SendRaw(heartbeat, 0);
 }
Exemplo n.º 20
0
        public void FromApp(QuickFix.Message msg, SessionID sessionID)
        {
            logMe("\r\n \r\n" + "FromApp :" + msg.ToString());

            try
            {
                if (msg is QuickFix.FIX42.OrderCancelReject)
                {
                    Console.WriteLine("Order Cancel Reject event raised");
                    QuickFix.FIX42.OrderCancelReject er = (QuickFix.FIX42.OrderCancelReject)msg;

                    if (er.IsSetClOrdID())
                    {
                        Console.WriteLine("ClOrdID : " + er.ClOrdID);
                    }
                    if (er.IsSetOrigClOrdID())
                    {
                        Console.WriteLine("OrigClOrdID : " + er.OrigClOrdID);
                    }
                    if (er.IsSetOrdStatus())
                    {
                        Console.WriteLine("OrderStatus : " + er.OrdStatus);
                    }
                    if (er.IsSetCxlRejResponseTo())
                    {
                        Console.WriteLine("CxlRejResponseTo : " + er.CxlRejResponseTo);
                    }
                    if (er.IsSetCxlRejReason())
                    {
                        Console.WriteLine("CxlRejReason : " + er.CxlRejReason);
                    }
                    if (er.IsSetOrderID())
                    {
                        Console.WriteLine("OrderID : " + er.OrderID);
                    }

                    if (er.CxlRejResponseTo.getValue() == CxlRejResponseTo.ORDER_CANCEL_REQUEST)
                    {
                        // Order Cancel Rejected reason
                        // 1= UNKNOWN_ORDER, 2 = Broker Option, 3 = Order already in Pending Cancel or Pending Replace status

                        string orderDetails = "CANCEL_REJECTED";
                        Int32  origOrderID  = -1;
                        if (er.IsSetOrigClOrdID())
                        {
                            origOrderID = Convert.ToInt32(er.OrigClOrdID.getValue());
                        }
                        Orders o = new Orders();
                        if (er.IsSetEncodedText())
                        {
                            orderDetails += " : " + er.EncodedText.getValue();
                        }
                        o.FIXResponseCanModRejectHandler(Convert.ToInt32(er.ClOrdID.getValue()), er.OrderID.getValue(), origOrderID, er.CxlRejResponseTo.getValue(), "CANCEL_" + getRejectType(er.CxlRejReason), orderDetails);
                    }
                    else if (er.CxlRejResponseTo.getValue() == CxlRejResponseTo.ORDER_CANCEL_REPLACE_REQUEST)
                    {
                        // Order modification Rejected reason
                        // 1 = Broker Option
                        // 3 = Order already in Pending Cancel or Pending Replace status

                        string orderDetails = "MODIFY_REJECTED";
                        Int32  origOrderID  = -1;
                        if (er.IsSetOrigClOrdID())
                        {
                            origOrderID = Convert.ToInt32(er.OrigClOrdID.getValue());
                        }
                        Orders o = new Orders();
                        if (er.IsSetEncodedText())
                        {
                            orderDetails += " : " + er.EncodedText.getValue();
                        }
                        o.FIXResponseCanModRejectHandler(Convert.ToInt32(er.ClOrdID.getValue()), er.OrderID.getValue(), origOrderID, er.CxlRejResponseTo.getValue(), "MODIFY_" + getRejectType(er.CxlRejReason), orderDetails);
                    }
                }
                else if (msg is QuickFix.FIX42.ExecutionReport)
                {
                    string ordTypeField = msg.GetField(40);
                    if (ordTypeField == "1")
                    {
                        IField field = new DecimalField(44, 0);
                        msg.SetField(field);
                    }

                    QuickFix.FIX42.ExecutionReport er = (QuickFix.FIX42.ExecutionReport)msg;
                    string orderDetails = Convert.ToString(er.ExecType.getValue()) + "|" + er.OrderQty.getValue() + "|" + er.Price.getValue() + "|" + er.LastShares.getValue() + "|" + er.LastPx.getValue() + "|" + er.CumQty.getValue() + "|" + er.AvgPx.getValue() + "|" + er.OrdType.getValue() + "|";
                    if (er.IsSetText())
                    {
                        orderDetails = orderDetails + er.Text + "|";
                    }
                    else
                    {
                        orderDetails = orderDetails + "NULL|";
                    }

                    logMe("\r\n \r\n" + "Got execution Report - ExecType = " + orderDetails);
                    Console.WriteLine("\r\n \r\n" + "Got execution Report - ExecType = " + orderDetails);
                    Orders o = new Orders();
                    if (er.ExecType.getValue() == ExecType.FILL || er.ExecType.getValue() == ExecType.PARTIAL_FILL)
                    {
                        o.FIXResponseHandlerForFill(Convert.ToInt32(er.ClOrdID.getValue()), er.OrderID.getValue(), (float)Convert.ToDouble(er.OrderQty.getValue()), (float)Convert.ToDouble(er.LastPx.getValue()), (float)Convert.ToDouble(er.LastShares.getValue()), getExecType(er.ExecType), er.ExecType.getValue());
                    }
                    else
                    {
                        Int32 origOrderID = -1;
                        float price       = -1;
                        char  orderType   = '2';
                        if (er.IsSetOrigClOrdID())
                        {
                            origOrderID = Convert.ToInt32(er.OrigClOrdID.getValue());
                        }
                        if (er.IsSetPrice())
                        {
                            price = (float)Convert.ToDouble(er.Price.getValue());
                        }
                        if (er.IsSetOrdType())
                        {
                            orderType = er.OrdType.getValue();
                        }

                        //orderid is string since value is too large for int variable
                        o.FIXResponseHandler(Convert.ToInt32(er.ClOrdID.getValue()), er.OrderID.getValue(), origOrderID, er.ExecType.getValue(), getExecType(er.ExecType), orderDetails, price, orderType);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("exception(FixClient FromAPP) " + e.Message);
            }
        }