Ejemplo n.º 1
0
        protected void NextSequenceReset(Message sequenceReset)
        {
            bool isGapFill = false;

            if (sequenceReset.IsSetField(Fields.Tags.GapFillFlag))
            {
                isGapFill = sequenceReset.GetBoolean(Fields.Tags.GapFillFlag);
            }

            if (!Verify(sequenceReset, isGapFill, isGapFill))
            {
                return;
            }

            if (sequenceReset.IsSetField(Fields.Tags.NewSeqNo))
            {
                int newSeqNo = sequenceReset.GetInt(Fields.Tags.NewSeqNo);
                this.Log.OnEvent("Received SequenceReset FROM: " + state_.GetNextTargetMsgSeqNum() + " TO: " + newSeqNo);

                if (newSeqNo > state_.GetNextTargetMsgSeqNum())
                {
                    state_.SetNextTargetMsgSeqNum(newSeqNo);
                }
                else
                {
                    if (newSeqNo < state_.GetNextTargetMsgSeqNum())
                    {
                        GenerateReject(sequenceReset, FixValues.SessionRejectReason.VALUE_IS_INCORRECT);
                    }
                }
            }
        }
Ejemplo 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();
            }
        }
Ejemplo n.º 3
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);
     }
 }
Ejemplo n.º 4
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));
            }
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
0
        protected void NextSequenceReset(Message sequenceReset)
        {
            bool isGapFill = false;
            if (sequenceReset.IsSetField(Fields.Tags.GapFillFlag))
                isGapFill = sequenceReset.GetBoolean(Fields.Tags.GapFillFlag);

            if (!Verify(sequenceReset, isGapFill, isGapFill))
                return;

            if (sequenceReset.IsSetField(Fields.Tags.NewSeqNo))
            {
                int newSeqNo = sequenceReset.GetInt(Fields.Tags.NewSeqNo);
                this.Log.OnEvent("Received SequenceReset FROM: " + state_.GetNextTargetMsgSeqNum() + " TO: " + newSeqNo);

                if (newSeqNo > state_.GetNextTargetMsgSeqNum())
                {
                    state_.SetNextTargetMsgSeqNum(newSeqNo);
                }
                else
                {
                    if (newSeqNo < state_.GetNextTargetMsgSeqNum())
                        GenerateReject(sequenceReset, FixValues.SessionRejectReason.VALUE_IS_INCORRECT);
                }
            }
        }
Ejemplo 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_.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);
        }
Ejemplo n.º 8
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));
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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);
            }
        }
Ejemplo n.º 11
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);
            }
        }
Ejemplo n.º 12
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);
            }
        }
Ejemplo n.º 13
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);
            }
        }
Ejemplo n.º 14
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);
            }
        }
Ejemplo n.º 15
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);
            }
        }