コード例 #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
ファイル: OKCMarketFIXAPI.cs プロジェクト: w1r2p1/crux
        /// <summary>
        /// Report after a request about orders is made
        /// Possible cause:
        /// - New order
        /// - Cancel order
        /// - Rejected order
        /// - Requested order info
        /// - Order filled or partially filled
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="sessionID"></param>
        public void OnMessage(QuickFix.FIX44.ExecutionReport msg, SessionID sessionID)
        {
            char executionReportType = msg.GetChar(Tags.ExecType);
            int  clientOrderID       = msg.GetInt(Tags.ClOrdID);

            switch (executionReportType)
            {
            case ExecType.NEW:
            {
                // New order execution report
                string avgPrice = msg.GetString(Tags.AvgPx);
                char   side     = msg.GetChar(Tags.Side);
                var    order    = new Order()
                {
                    OrderID       = msg.GetString(Tags.ExecID),
                    ClientOrderID = clientOrderID,
                    Price         = double.Parse(avgPrice),
                    Side          = side
                };
                CurrentOrders.Add(order);
                OrderSubmitCallback?.Invoke(false);
                OrderSubmitCallback = null;
                Log.Write($"Submission confirmed {order}", 2);
                break;
            }

            case ExecType.PARTIAL_FILL:
            {
                // Order executed
                double executionPrice = (double)msg.GetDecimal(Tags.AvgPx);
                int    orderStatus    = msg.GetInt(Tags.OrdStatus);
                char   side           = msg.GetChar(Tags.Side);

                double remainingQty = (double)msg.GetDecimal(Tags.LeavesQty);
                var    order        = CurrentOrders.First(o => o.ClientOrderID == clientOrderID);
                order.FilledVolume = order.Volume - remainingQty;
                Log.Write($"Partial fill {order}", 2);
                break;
            }

            case ExecType.FILL:
            {
                // Order executed
                double executionPrice = (double)msg.GetDecimal(Tags.AvgPx);
                int    orderStatus    = msg.GetInt(Tags.OrdStatus);
                char   side           = msg.GetChar(Tags.Side);
                var    order          = CurrentOrders.First(o => o.ClientOrderID == clientOrderID);
                order.FilledVolume = order.Volume;
                //CurrentOrders.Remove(order);
                Log.Write($"Fill {order}", 2);
                break;
            }

            case ExecType.CANCELED:
            {
                // Order cancel report
                string orderID = msg.GetString(Tags.ExecID);
                CurrentOrders.RemoveAll(o => o.ClientOrderID == clientOrderID);
                OrderCancelCallback?.Invoke(false);
                OrderCancelCallback = null;
                break;
            }

            case ExecType.REJECTED:
            {
                // Rejected order execution report
                OrderSubmitCallback?.Invoke(true);
                OrderSubmitCallback = null;
                string orderStatus = msg.GetString(Tags.OrdStatus);
                string text        = msg.GetString(Tags.Text);
                Log.Write($"Order rejected | status: {orderStatus} | reason: {text}", 1);
                break;
            }

            case ExecType.PENDING_NEW:
            {
                // Requested Order info
                int numReports = msg.GetInt(Tags.TotNumReports);
                if (!CurrentOrders.Exists(o => o.ClientOrderID.Equals(clientOrderID)))
                {
                    CurrentOrders.Add(new Order()
                        {
                            OrderID       = msg.GetString(Tags.OrderID),
                            ClientOrderID = clientOrderID,
                            Price         = (double)msg.GetDecimal(Tags.AvgPx),
                            Side          = msg.GetChar(Tags.Side)
                        });
                }
                break;
            }

            default:
                Log.Write($"Unknown execution report type {executionReportType}", 0);
                break;
            }
        }
コード例 #3
0
        public void OnMessage(QuickFix.FIX44.ExecutionReport m, SessionID s)
        {
            var utcNow = DateTime.UtcNow;

            var stringBuilder = new StringBuilder("***Execution report***:\r\n");

            stringBuilder.Append("================\r\n");
            for (int i = 1; i <= m.GetInt(QuickFix.Fields.Tags.NoContraBrokers); i++)
            {
                var group = new QuickFix.FIX44.ExecutionReport.NoContraBrokersGroup();
                m.GetGroup(i, group);
                stringBuilder.Append("LP:").Append(group.ContraBroker.getValue()).Append("\r\n");
            }
            stringBuilder.Append("Price:").Append(m.AvgPx.getValue()).Append("\r\n");
            stringBuilder.Append("Side:").Append(m.Side.getValue() == '1'?"Buy" :"Sell").Append("\r\n");
            stringBuilder.Append("Quantity:").Append(m.OrderQty.getValue()).Append("\r\n");

            var TimeIn        = default(DateTime);
            var TimeOut       = default(DateTime);
            var BrokerReceipt = default(DateTime);
            var BrokerExec    = default(DateTime);

            for (int i = 1; i <= m.GetInt(QuickFix.Fields.Tags.NoTrdRegTimestamps); i++)
            {
                var group = new QuickFix.FIX44.CollateralReport.NoTrdRegTimestampsGroup();
                m.GetGroup(i, group);
                switch (i)
                {
                case 1:
                    TimeIn = group.TrdRegTimestamp.getValue();
                    break;

                case 2:
                    TimeOut = group.TrdRegTimestamp.getValue();
                    break;

                case 3:
                    BrokerReceipt = group.TrdRegTimestamp.getValue();
                    break;

                case 4:
                    BrokerExec = group.TrdRegTimestamp.getValue();
                    break;
                }
            }
            var clientSentDate = this._orderClientTimestamp[m.ClOrdID.getValue()];


            stringBuilder.Append("TimeStamps:\r\n");
            stringBuilder.Append("Customer sent:").Append(clientSentDate.ToString("h:m:s.fff")).Append("\r\n");
            stringBuilder.Append("Time in:").Append(TimeIn.ToString("h:m:s.fff")).Append("\r\n");
            stringBuilder.Append("Broker receipt:").Append(BrokerReceipt.ToString("h:m:s.fff")).Append("\r\n");
            stringBuilder.Append("Broker exec:").Append(BrokerExec.ToString("h:m:s.fff")).Append("\r\n");
            stringBuilder.Append("Time out:").Append(TimeOut.ToString("h:m:s.fff")).Append("\r\n");
            stringBuilder.Append("Customer exec:").Append(utcNow.ToString("h:m:s.fff")).Append("\r\n");


            stringBuilder.Append("Customer       |  IdsRoot   |  LP\r\n").Append("\r\n");
            stringBuilder.Append("Customer sent->|            |\r\n").Append("\r\n");
            stringBuilder.Append("               |-> Time in  |\r\n").Append("\r\n");
            stringBuilder.Append("               |            |-> Broker Receipt\r\n").Append("\r\n");
            stringBuilder.Append("               |            |<- Broker exec\r\n").Append("\r\n");
            stringBuilder.Append("               |<- Time out |\r\n").Append("\r\n");
            stringBuilder.Append("Customer exec<-|            |\r\n").Append("\r\n");
            Console.WriteLine(stringBuilder.ToString());
        }