Пример #1
0
        public static OrdemInfo Fix44ExecutionReport2OrdemInfo(QuickFix.FIX44.ExecutionReport er, FixSessionItem cfg)
        {
            try
            {
                OrdemInfo order     = new OrdemInfo();
                string    descricao = string.Empty;

                // order = new OrdemInfo();
                order.Account     = Convert.ToInt32(er.IsSetAccount() ? er.Account.getValue() : "0");
                order.Exchange    = cfg.Bolsa;
                order.ChannelID   = cfg.Operador;
                order.ClOrdID     = er.ClOrdID.ToString();//chaveClOrdId;
                order.OrigClOrdID = er.IsSetOrigClOrdID() ? er.OrigClOrdID.getValue() : null;
                order.ExecBroker  = "227";
                if (er.IsSetExpireDate())
                {
                    string expdate = er.ExpireDate.getValue() + "235959";
                    order.ExpireDate = DateTime.ParseExact(expdate, "yyyyMMddHHmmss", CultureInfo.InvariantCulture);
                }
                else
                {
                    order.ExpireDate = DateTime.MinValue;
                }
                order.MaxFloor    = er.IsSetMaxFloor() ? Convert.ToDouble(er.MaxFloor.getValue()) : 0;
                order.MinQty      = er.IsSetMinQty() ? Convert.ToDouble(er.MinQty.getValue()) : 0;
                order.OrderQty    = Convert.ToInt32(er.IsSetOrderQty() ? er.OrderQty.getValue() : 0);
                order.OrdType     = FixMessageUtilities.TraduzirOrdemTipo(er.OrdType.getValue());
                order.Price       = er.IsSetPrice() ? Convert.ToDouble(er.Price.getValue()) : 0;
                order.SecurityID  = er.IsSetSecurityID() ? er.SecurityID.ToString() : null;
                order.Side        = er.IsSetSide() ? (OrdemDirecaoEnum)Convert.ToInt32(er.Side.ToString()) : OrdemDirecaoEnum.NaoInformado;
                order.Symbol      = er.IsSetSymbol() ? er.Symbol.ToString() : null;
                order.TimeInForce = er.IsSetTimeInForce() ? FixMessageUtilities.deTimeInForceParaOrdemValidade(er.TimeInForce) : OrdemValidadeEnum.NaoInformado;
                //}

                order.ExchangeNumberID   = er.IsSetOrderID() ? er.OrderID.getValue() : null;
                order.OrderQtyRemmaining = Convert.ToInt32(er.IsSetLeavesQty() ? er.LeavesQty.getValue() : 0);
                order.CumQty             = Convert.ToInt32(er.IsSetCumQty() ? er.CumQty.getValue() : 0);
                order.OrdStatus          = FixMessageUtilities.TraduzirOrdemStatus(er.OrdStatus.getValue());
                order.Memo5149           = er.IsSetField(5149) ? er.GetField(5149) : String.Empty;
                order.PossDupFlag        = er.Header.IsSetField(Tags.PossDupFlag) ? er.Header.GetBoolean(Tags.PossDupFlag) : false;
                order.PossResend         = er.Header.IsSetField(Tags.PossResend) ? er.Header.GetBoolean(Tags.PossResend) : false;
                order.CompIDBolsa        = er.Header.IsSetField(Tags.SenderCompID) ? er.Header.GetString(Tags.SenderCompID) : cfg.SenderCompID;
                order.CompIDOMS          = er.Header.IsSetField(Tags.TargetCompID) ? er.Header.GetString(Tags.TargetCompID) : cfg.TargetCompID;

                switch (order.OrdStatus)
                {
                case OrdemStatusEnum.NOVA:
                    descricao          = "Ordem aberta";
                    order.RegisterTime = DateTime.Now;
                    break;

                case OrdemStatusEnum.CANCELADA:
                    descricao = "Ordem cancelada";
                    break;

                case OrdemStatusEnum.PARCIALMENTEEXECUTADA:
                    descricao = "Ordem com execucao parcial";
                    break;

                case OrdemStatusEnum.SUSPENSA:
                    descricao = "Ordem suspensa";
                    break;

                case OrdemStatusEnum.EXECUTADA:
                    descricao = "Ordem executada";
                    break;

                case OrdemStatusEnum.SUBSTITUIDA:
                    descricao = "Ordem substituida";
                    break;

                case OrdemStatusEnum.REJEITADA:
                    if (er.IsSetText())
                    {
                        descricao = er.Text.getValue();
                    }
                    break;
                }
                order.TransactTime = DateTime.Now;
                // Try get the msg seq number
                order.FixMsgSeqNum    = er.Header.IsSetField(Tags.MsgSeqNum) ? er.Header.GetInt(Tags.MsgSeqNum) : 0;
                order.ProtectionPrice = Convert.ToDecimal(er.IsSetField(35001) ? er.GetString(35001) : "0");


                // Setando informações de acompanhamento
                AcompanhamentoOrdemInfo acompanhamento = new AcompanhamentoOrdemInfo();
                acompanhamento.NumeroControleOrdem    = order.ClOrdID;
                acompanhamento.CodigoDoCliente        = order.Account;
                acompanhamento.CodigoResposta         = order.ExchangeNumberID;
                acompanhamento.CodigoTransacao        = er.IsSetExecID() ? er.ExecID.getValue() : null;
                acompanhamento.Instrumento            = order.Symbol;
                acompanhamento.SecurityID             = order.SecurityID;
                acompanhamento.CanalNegociacao        = order.ChannelID;
                acompanhamento.Direcao                = order.Side;
                acompanhamento.QuantidadeSolicitada   = order.OrderQty;
                acompanhamento.QuantidadeExecutada    = (int)er.CumQty.getValue();
                acompanhamento.QuantidadeRemanescente = (int)er.LeavesQty.getValue();
                acompanhamento.QuantidadeNegociada    = er.IsSetLastQty() ? (int)er.LastQty.getValue() : 0;
                acompanhamento.Preco           = new Decimal(order.Price);
                acompanhamento.StatusOrdem     = FixMessageUtilities.TraduzirOrdemStatus(er.OrdStatus.getValue());
                acompanhamento.DataOrdemEnvio  = order.TransactTime;
                acompanhamento.DataAtualizacao = DateTime.Now;
                acompanhamento.CodigoRejeicao  = er.IsSetOrdRejReason() ? er.OrdRejReason.ToString() : "0";
                acompanhamento.Descricao       = descricao;
                // Try get the msg seq number
                acompanhamento.FixMsgSeqNum = er.Header.IsSetField(Tags.MsgSeqNum) ? er.Header.GetInt(Tags.MsgSeqNum) : 0;
                acompanhamento.LastPx       = er.IsSetLastPx() ? (Decimal)er.LastPx.getValue() : new Decimal(order.Price);
                acompanhamento.TradeDate    = er.IsSetTradeDate() ? er.TradeDate.getValue() : DateTime.Now.ToString("yyyyMMdd");

                //BEI Fields
                //Added in 2012-Nov-13 by ATP
                acompanhamento.ExchangeOrderID          = er.IsSetField(35022) ? er.GetString(35022) : String.Empty;
                acompanhamento.ExchangeExecID           = er.IsSetField(35023) ? er.GetString(35023) : String.Empty;
                acompanhamento.LastPxInIssuedCurrency   = Convert.ToDecimal(er.IsSetField(35024) ? er.GetString(35024) : "0");
                acompanhamento.PriceInIssuedCurrency    = Convert.ToDecimal(er.IsSetField(35025) ? er.GetString(35025) : "0");
                acompanhamento.ExchangeSecondaryOrderID = er.IsSetField(35026) ? er.GetString(35026) : String.Empty;
                acompanhamento.TradeLinkID     = er.IsSetField(820) ? er.GetString(820) : String.Empty;
                acompanhamento.OrderLinkID     = er.IsSetField(5975) ? er.GetString(5975) : String.Empty;
                acompanhamento.ExchangeQuoteID = er.IsSetField(5001) ? er.GetString(5001) : String.Empty;
                acompanhamento.PossDupFlag     = er.Header.IsSetField(Tags.PossDupFlag) ? er.Header.GetBoolean(Tags.PossDupFlag) : false;
                acompanhamento.PossResend      = er.Header.IsSetField(Tags.PossResend) ? er.Header.GetBoolean(Tags.PossResend) : false;
                acompanhamento.CompIDBolsa     = er.Header.IsSetField(Tags.SenderCompID) ? er.Header.GetString(Tags.SenderCompID) : cfg.SenderCompID;
                acompanhamento.CompIDOMS       = er.Header.IsSetField(Tags.TargetCompID) ? er.Header.GetString(Tags.TargetCompID) : cfg.TargetCompID;

                if (er.IsSetNoMiscFees())
                {
                    int ocorr = er.GetInt(Tags.NoMiscFees);// noMiscFees.getValue();

                    for (uint i = 0; i < ocorr; i++)
                    {
                        EmolumentoInfo emol     = new EmolumentoInfo();
                        Group          feeGroup = er.GetGroup((int)i, Tags.NoMiscFees);
                        emol.Valor          = Convert.ToDecimal(feeGroup.IsSetField(Tags.MiscFeeAmt) ? feeGroup.GetString(Tags.MiscFeeAmt) : "0");
                        emol.BaseEmolumento = Convert.ToInt32(feeGroup.IsSetField(Tags.MiscFeeBasis) ? feeGroup.GetString(Tags.MiscFeeBasis) : "0");
                        emol.Currency       = feeGroup.GetString(Tags.MiscFeeCurr);
                        emol.Tipo           = (EmolumentoTipoEnum)feeGroup.GetInt(Tags.MiscFeeType);
                    }
                }

                // Adicionando informações de acompanhamento ao OrdemInfo
                order.Acompanhamentos.Clear();
                order.Acompanhamentos.Add(acompanhamento);

                return(order);
            }
            catch (Exception ex)
            {
                logger.Error("Fix44ExecutionReport2OrdemInfo(): " + ex.Message, ex);
            }
            return(null);
        }
Пример #2
0
        public static QuickFix.FIX42.ExecutionReport Fix44ER_2_Fix42ER(QuickFix.FIX44.ExecutionReport er44)
        {
            try
            {
                QuickFix.FIX42.ExecutionReport er42 = new QuickFix.FIX42.ExecutionReport();
                // if (er44.IsSetApplID()) er42.Set(new ApplID(er44.ApplID.getValue()));
                // if (er44.IsSetApplSeqNum()) er42.Set(new ApplSeqNum(er44.ApplSeqNum.getValue()));
                if (er44.IsSetOrderID())
                {
                    er42.Set(new OrderID(er44.OrderID.getValue()));
                }
                if (er44.IsSetSecondaryOrderID())
                {
                    er42.Set(new SecondaryOrderID(er44.SecondaryOrderID.getValue()));
                }
                // if (er44.IsSetSecondaryExecID()) er42.Set(new SecondaryExecID(er44.SecondaryExecID.getValue()));
                if (er44.IsSetClOrdID())
                {
                    er42.Set(new ClOrdID(er44.ClOrdID.getValue()));
                }
                if (er44.IsSetOrigClOrdID())
                {
                    er42.Set(new OrigClOrdID(er44.OrigClOrdID.getValue()));
                }
                //if (er44.IsSetNoPartyIDs()) er42.Set(new NoPartyIDs(er44.NoPartyIDs.getValue()));
                //if (er44.IsSetPartyID()) er42.Set(new PartyID(er44.PartyID.getValue()));
                //if (er44.IsSetPartyIDSource()) er42.Set(new PartyIDSource(er44.PartyIDSource.getValue()));
                //if (er44.IsSetPartyRole()) er42.Set(new PartyRole(er44.PartyRole.getValue()));

                // TODO[FF] - Montagem dos grupos
                if (er44.IsSetNoContraBrokers())
                {
                    er42.Set(new NoContraBrokers(er44.NoContraBrokers.getValue()));
                    int len = er44.NoContraBrokers.getValue();
                    for (int i = 1; i <= len; i++)
                    {
                        Group grp = er44.GetGroup(i, Tags.NoContraBrokers);
                        er42.AddGroup(grp);
                    }
                }

                //if (er44.IsSetContra ContraBroker()) er42.Set(new ContraBroker(er44.ContraBroker.getValue()));
                // if (er44.IsSetCrossID()) er42.Set(new CrossID(er44.CrossID.getValue()));
                if (er44.IsSetExecID())
                {
                    er42.Set(new ExecID(er44.ExecID.getValue()));
                }
                if (er44.IsSetExecRefID())
                {
                    er42.Set(new ExecRefID(er44.ExecRefID.getValue()));
                }
                if (er44.IsSetExecType())
                {
                    er42.Set(new ExecType(er44.ExecType.getValue()));
                }
                if (er44.IsSetOrdStatus())
                {
                    er42.Set(new OrdStatus(er44.OrdStatus.getValue()));
                }
                // if (er44.IsSetWorkingIndicator()) er42.Set(new WorkingIndicator(er44.WorkingIndicator.getValue()));
                //if (er44.IsSetOrdRejReason()) er42.Set(new OrdRejReason(er44.OrdRejReason.getValue()));
                if (er44.IsSetOrdRejReason())
                {
                    er42.Set(new OrdRejReason(99));                           // Will always set "99" - other
                }
                if (er44.IsSetExecRestatementReason())
                {
                    er42.Set(new ExecRestatementReason(er44.ExecRestatementReason.getValue()));
                }
                if (er44.IsSetAccount())
                {
                    er42.Set(new Account(er44.Account.getValue()));
                }
                // if (er44.IsSetAccountType()) er42.Set(new AccountType(er44.AccountType.getValue()));
                if (er44.IsSetSettlType())
                {
                    er42.Set(new SettlmntTyp(er44.SettlType.getValue()[0]));
                }
                // if (er44.IsSetDaysToSettlement()) er42.Set(new DaysToSettlement(er44.DaysToSettlement.getValue()));
                // if (er44.IsSetFixedRate()) er42.Set(new FixedRate(er44.FixedRate.getValue()));
                if (er44.IsSetSymbol())
                {
                    er42.Set(new Symbol(er44.Symbol.getValue()));
                }
                if (er44.IsSetSecurityID())
                {
                    er42.Set(new SecurityID(er44.SecurityID.getValue()));
                }
                // if (er44.IsSetSecurityIDSource()) er42.Set(new SecurityIDSource(er44.SecurityIDSource.getValue()));
                if (er44.IsSetSecurityExchange())
                {
                    er42.Set(new SecurityExchange(er44.SecurityExchange.getValue()));
                }
                if (er44.IsSetSide())
                {
                    er42.Set(new Side(er44.Side.getValue()));
                }
                if (er44.IsSetOrderQty())
                {
                    er42.Set(new OrderQty(er44.OrderQty.getValue()));
                }
                if (er44.IsSetOrdType())
                {
                    er42.Set(new OrdType(er44.OrdType.getValue()));
                }
                if (er44.IsSetPrice())
                {
                    er42.Set(new Price(er44.Price.getValue()));
                }
                if (er44.IsSetStopPx())
                {
                    er42.Set(new StopPx(er44.StopPx.getValue()));
                }
                // if (er44.IsSetProtectionPrice()) er42.Set(new ProtectionPrice(er44.ProtectionPrice.getValue()));
                if (er44.IsSetCurrency())
                {
                    er42.Set(new Currency(er44.Currency.getValue()));
                }
                if (er44.IsSetTimeInForce())
                {
                    er42.Set(new TimeInForce(er44.TimeInForce.getValue()));
                }
                if (er44.IsSetExpireDate())
                {
                    er42.Set(new ExpireDate(er44.ExpireDate.getValue()));
                }
                if (er44.IsSetLastQty())
                {
                    er42.Set(new LastShares(er44.LastQty.getValue()));
                }
                if (er44.IsSetLastPx())
                {
                    er42.Set(new LastPx(er44.LastPx.getValue()));
                }
                if (er44.IsSetLeavesQty())
                {
                    er42.Set(new LeavesQty(er44.LeavesQty.getValue()));
                }
                if (er44.IsSetCumQty())
                {
                    er42.Set(new CumQty(er44.CumQty.getValue()));
                }
                if (er44.IsSetAvgPx())
                {
                    er42.Set(new AvgPx(er44.AvgPx.getValue()));
                }
                if (er44.IsSetTradeDate())
                {
                    er42.Set(new TradeDate(er44.TradeDate.getValue()));
                }
                if (er44.IsSetTransactTime())
                {
                    er42.Set(new TransactTime(er44.TransactTime.getValue()));
                }
                // if (er44.IsSetAggressorIndicator()) er42.Set(new AggressorIndicator(er44.AggressorIndicator.getValue()));
                if (er44.IsSetMinQty())
                {
                    er42.Set(new MinQty(er44.MinQty.getValue()));
                }
                if (er44.IsSetMaxFloor())
                {
                    er42.Set(new MaxFloor(er44.MaxFloor.getValue()));
                }
                if (er44.IsSetText())
                {
                    er42.Set(new Text(er44.Text.getValue()));
                }
                if (er44.IsSetMultiLegReportingType())
                {
                    er42.Set(new MultiLegReportingType(er44.MultiLegReportingType.getValue()));
                }
                // if (er44.IsSetTotNoRelatedSym()) er42.Set(new TotNoRelatedSym(er44.TotNoRelatedSym.getValue()));
                // if (er44.IsSetNoMiscFees()) er42.Set(new NoMiscFees(er44.NoMiscFees.getValue()));
                // if (er44.IsSetMiscFeeAmt()) er42.Set(new MiscFeeAmt(er44.MiscFeeAmt.getValue()));
                // if (er44.IsSetMiscFeeCurr()) er42.Set(new MiscFeeCurr(er44.MiscFeeCurr.getValue()));
                // if (er44.IsSetMiscFeeType()) er42.Set(new MiscFeeType(er44.MiscFeeType.getValue()));
                // if (er44.IsSetMiscFeeBasis()) er42.Set(new MiscFeeBasis(er44.MiscFeeBasis.getValue()));
                // if (er44.IsSetUniqueTradeID()) er42.Set(new UniqueTradeID(er44.UniqueTradeID.getValue()));
                // if (er44.IsSetTradeLinkID()) er42.Set(new TradeLinkID(er44.TradeLinkID.getValue()));
                // if (er44.IsSetOrderLinkID()) er42.Set(new OrderLinkID(er44.OrderLinkID.getValue()));
                // if (er44.IsSetExchangeQuoteID()) er42.Set(new ExchangeQuoteID(er44.ExchangeQuoteID.getValue()));
                // if (er44.IsSetExchangeOrderID()) er42.Set(new ExchangeOrderID(er44.ExchangeOrderID.getValue()));
                // if (er44.IsSetExchangeExecID()) er42.Set(new ExchangeExecID(er44.ExchangeExecID.getValue()));
                // if (er44.IsSetLastPxInIssuedCurrency()) er42.Set(new LastPxInIssuedCurrency(er44.LastPxInIssuedCurrency.getValue()));
                // if (er44.IsSetPriceInIssuedCurrency()) er42.Set(new PriceInIssuedCurrency(er44.PriceInIssuedCurrency.getValue()));
                // if (er44.IsSetExchangeSecondaryOrderID()) er42.Set(new ExchangeSecondaryOrderID(er44.ExchangeSecondaryOrderID.getValue()));
                // if (er44.IsSetOrderCategory()) er42.Set(new OrderCategory(er44.OrderCategory.getValue()));
                if (er44.IsSetField(Tags.Memo))
                {
                    er42.SetField(new Memo(er44.GetField(Tags.Memo)));
                }

                // Validacao campo ExecTransType
                switch (er44.OrdStatus.getValue())
                {
                case OrdStatus.NEW:
                    er42.Set(new ExecTransType(ExecTransType.NEW));
                    break;

                case OrdStatus.CANCELED:
                case OrdStatus.REPLACED:     // TODO [FF] - Rever se o tratamento esta correto
                    er42.Set(new ExecTransType(ExecTransType.STATUS));
                    // er42.Set(new ExecRefID(er44.ExecRefID.getValue()));
                    break;

                case OrdStatus.REJECTED:
                case OrdStatus.FILLED:
                case OrdStatus.PARTIALLY_FILLED:
                    er42.Set(new ExecTransType(ExecTransType.STATUS));
                    er42.Set(new ExecType(er44.OrdStatus.getValue()));     // 4.2 nao aceita ExecType=F
                    break;

                case OrdStatus.EXPIRED:
                    er42.Set(new ExecTransType(ExecTransType.STATUS));
                    er42.Set(new OrdStatus(OrdStatus.DONE_FOR_DAY));
                    er42.Set(new ExecType(ExecType.DONE_FOR_DAY));
                    break;
                }
                // Validacao campo


                /*
                 * if (er44.IsSetAvgPx()) er42.Set(new AvgPx(er44.AvgPx.getValue()));
                 * if (er44.IsSetClOrdID()) er42.Set(new ClOrdID(er44.ClOrdID.getValue()));
                 * if (er44.IsSetCommission()) er42.Set(new Commission(er44.Commission.getValue()));
                 * if (er44.IsSetCommType()) er42.Set(new CommType(er44.CommType.getValue()));
                 * if (er44.IsSetCumQty()) er42.Set(new CumQty(er44.CumQty.getValue()));
                 * if (er44.IsSetCurrency()) er42.Set(new Currency(er44.Currency.getValue()));
                 * if (er44.IsSetExecID()) er42.Set(new ExecID(er44.ExecID.getValue()));
                 * if (er44.IsSetExecRefID()) er42.Set(new ExecRefID(er44.ExecRefID.getValue()));
                 *
                 * //if (er44.IsSetExecTransType()) er42.Set(new ExecTransType(er44.ExecTransType.getValue())); // TODO[FF] - Verificar o gerenciamento deste campo
                 * if (er44.IsSetExecType()) er42.Set(new ExecType(er44.ExecType.getValue()));
                 * // if (er44.IsSetIDSource()) er42.Set(new IDSource(er44.IDSource.getValue())); // TODO[FF] - Verificar o gerenciamento deste campo
                 * if (er44.IsSetLastPx()) er42.Set(new LastPx(er44.LastPx.getValue()));
                 * // if (er44.IsSetLastShares()) er42.Set(new LastShares(er44.LastShares.getValue())); // TODO[FF] - Verificar o gerenciamento deste campo
                 * if (er44.IsSetLeavesQty()) er42.Set(new LeavesQty(er44.LeavesQty.getValue()));
                 * //if (er44.IsSetNoMiscFees()) er42.Set(new NoMiscFees(er44.NoMiscFees.getValue())); // TODO[FF] - Verificar o gerenciamento deste campo por ser group
                 * //if (er44.IsSetMiscFeeAmt()) er42.Set(new MiscFeeAmt(er44.MiscFeeAmt.getValue())); // TODO[FF] - Verificar o gerenciamento deste campo por ser elemento do group
                 * if (er44.IsSetOrderID()) er42.Set(new OrderID(er44.OrderID.getValue()));
                 * if (er44.IsSetOrderQty()) er42.Set(new OrderQty(er44.OrderQty.getValue()));
                 * if (er44.IsSetOrdStatus()) er42.Set(new OrdStatus(er44.OrdStatus.getValue()));
                 * if (er44.IsSetOrdType()) er42.Set(new OrdType(er44.OrdType.getValue()));
                 * if (er44.IsSetOrigClOrdID()) er42.Set(new OrigClOrdID(er44.OrigClOrdID.getValue()));
                 * if (er44.IsSetSecurityID()) er42.Set(new SecurityID(er44.SecurityID.getValue()));
                 * if (er44.IsSetSide()) er42.Set(new Side(er44.Side.getValue()));
                 * if (er44.IsSetSymbol()) er42.Set(new Symbol(er44.Symbol.getValue()));
                 * if (er44.IsSetTransactTime()) er42.Set(new TransactTime(er44.TransactTime.getValue()));
                 * if (er44.IsSetSecurityType()) er42.Set(new SecurityType(er44.SecurityType.getValue()));
                 * if (er44.IsSetSecurityExchange()) er42.Set(new SecurityExchange(er44.SecurityExchange.getValue()));
                 */
                return(er42);
            }
            catch (Exception ex)
            {
                logger.Error("Fix44ER_2_Fix42ER(): " + ex.Message, ex);
                return(null);
            }
        }