Exemple #1
0
        protected void ProcesssExecutionReportMessage(object param)
        {
            try
            {
                QuickFix.FIX44.ExecutionReport execReport = (QuickFix.FIX44.ExecutionReport)param;
                string clOrdId = execReport.GetString(QuickFix.Fields.Tags.ClOrdID);

                lock (tLock)
                {
                    if (SentOrders.ContainsKey(clOrdId))
                    {
                        string sender = SentOrders[clOrdId];

                        if (TestingModules.ContainsKey(sender))
                        {
                            FIXExecutionReportWrapper wrapper = new FIXExecutionReportWrapper(clOrdId, execReport, Configuration);
                            TestingModules[sender].ProcessMessage(wrapper);
                        }
                        else
                        {
                            DoLog(string.Format("{0}-Unknown sender @{1} ", Configuration.Name, sender), Fwk.Main.Common.Util.Constants.MessageType.Error);
                        }
                    }
                    else
                    {
                        DoLog(string.Format("{0}-Ignoring unknown ClOrdId execution report @{1} ", Configuration.Name, clOrdId), Fwk.Main.Common.Util.Constants.MessageType.Information);
                    }
                }
            }
            catch (Exception ex)
            {
                DoLog(string.Format("Critical error processing execution report @{0}:{1}", Configuration.Name, ex.Message), Fwk.Main.Common.Util.Constants.MessageType.Error);
            }
        }
        /// <summary>
        /// Makes an order object
        /// </summary>
        /// <param name="executionReport"></param>
        /// <returns></returns>
        private Order PopulateOder(QuickFix.FIX44.ExecutionReport executionReport)
        {
            string orderSide = FixCommon.Converter.ConvertOrderSide.GetLocalOrderSide(executionReport.Side.getValue());

            // Extract Order information
            Order order = new Order(_provider)
            {
                OrderID   = executionReport.ExecType.getValue().Equals(ExecType.NEW) ? executionReport.ClOrdID.getValue() : executionReport.OrigClOrdID.getValue(),
                OrderSide = orderSide,
                OrderSize = Convert.ToInt32(executionReport.OrderQty.getValue(), CultureInfo.InvariantCulture),
                Security  = new Security()
                {
                    Symbol = executionReport.Symbol.getValue()
                }
                //OrderTif = FixCommon.Converter.ConvertTif.GetLocalValue(executionReport.TimeInForce.getValue())
            };

            return(order);
        }
        /// <summary>
        /// Makes an execution object
        /// </summary>
        /// <param name="executionReport"></param>
        /// <returns></returns>
        private Execution PopulateExecution(QuickFix.FIX44.ExecutionReport executionReport)
        {
            string orderSide = FixCommon.Converter.ConvertOrderSide.GetLocalOrderSide(executionReport.Side.getValue());

            // Extract Fill information
            Fill fill = new Fill(new Security {
                Symbol = executionReport.Symbol.getValue()
            },
                                 _provider, executionReport.ClOrdID.getValue())
            {
                ExecutionDateTime = executionReport.TransactTime.getValue(),
                ExecutionType     =
                    executionReport.OrdStatus.getValue() == FixCommon.Constants.FixOrderStatus.Filled
                        ? Constants.ExecutionType.Fill
                        : Constants.ExecutionType.Partial,
                ExecutionId           = executionReport.ExecID.getValue(),
                ExecutionPrice        = Convert.ToDecimal(executionReport.AvgPx.getValue(), CultureInfo.InvariantCulture),
                ExecutionSize         = Convert.ToInt32(executionReport.CumQty.getValue(), CultureInfo.InvariantCulture) - Convert.ToInt32(executionReport.LeavesQty.getValue(), CultureInfo.InvariantCulture),
                ExecutionSide         = orderSide,
                AverageExecutionPrice = Convert.ToDecimal(executionReport.AvgPx.getValue(), CultureInfo.InvariantCulture),
                LeavesQuantity        = Convert.ToInt32(executionReport.LeavesQty.getValue(), CultureInfo.InvariantCulture),
                CummalativeQuantity   = Convert.ToInt32(executionReport.CumQty.getValue(), CultureInfo.InvariantCulture)
            };

            // Extract Order information
            Order order = new Order(_provider)
            {
                OrderID   = executionReport.ClOrdID.getValue(),
                OrderSide = orderSide,
                OrderSize = Convert.ToInt32(executionReport.OrderQty.getValue(), CultureInfo.InvariantCulture),
                Security  = new Security()
                {
                    Symbol = executionReport.Symbol.getValue()
                }
                //OrderTif = FixCommon.Converter.ConvertTif.GetLocalValue(executionReport.TimeInForce.getValue())
            };

            return(new Execution(fill, order));
        }
Exemple #4
0
        public void OnMessage(QuickFix.FIX44.ExecutionReport m, SessionID s)
        {
            _mainform._addMsg("Received execution report (4.4)\r\n");

            string msg = "Order Dump Begin =======================\r\n";

            msg += "\r\n";

            msg += "OrdemInfo:\r\n";
            msg += "==========\r\n";
            msg += "Account .........: " + m.Account.getValue() + "\r\n";
            msg += "Numero da ordem .: " + m.ClOrdID.getValue() + "\r\n";
            msg += "Symbol ..........: " + m.Symbol.getValue() + "\r\n";
            msg += "ExchangeNumber ..: " + m.OrderID.getValue() + "\r\n";
            msg += "Status ..........: " + m.OrdStatus.getValue() + "\r\n";
            msg += "Status ..........: " + FixMessageUtilities.TraduzirOrdemStatus(m.OrdStatus.getValue()) + "\r\n";
            msg += "Quantidade ......: " + m.OrderQty.getValue() + "\r\n";
            msg += "Qtde restante ...: " + (m.OrderQty.getValue() - m.CumQty.getValue()) + "\r\n";
            if (m.IsSetLastPx())
            {
                msg += "Preco ...........: " + m.LastPx.getValue() + "\r\n";
            }

            if (m.IsSetText())
            {
                msg += "Text ............: [" + m.Text.getValue() + "]\r\n";
            }

            if (m.IsSetField(5149))
            {
                msg += "Memo5149 ........: " + m.GetString(5149) + "\r\n";
            }

            msg += "\r\n";

            msg += "\r\nOrder Dump End =========================\r\n";

            _mainform._addMsg(msg);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="executionReport">Execution report</param>
        /// <param name="sessionId">Session ID</param>
        private void OnMessage(QuickFix.FIX44.ExecutionReport executionReport, SessionID sessionId)
        {
            try
            {
                switch (executionReport.ExecType.getValue())
                {
                case ExecType.NEW:
                {
                    Order order = PopulateOder(executionReport);
                    if (Logger.IsDebugEnabled)
                    {
                        Logger.Debug("New arrived : " + order, _type.FullName, "OnMessage");
                    }
                    if (NewArrived != null)
                    {
                        NewArrived(order);
                    }
                    break;
                }

                case ExecType.CANCELED:
                {
                    Order order = PopulateOder(executionReport);
                    if (Logger.IsDebugEnabled)
                    {
                        Logger.Debug("Cancellation arrived : " + order, _type.FullName, "OnMessage");
                    }
                    if (CancellationArrived != null)
                    {
                        CancellationArrived(order);
                    }
                    break;
                }

                case ExecType.REJECTED:

                    var rejection = ExtractOrderRejection(executionReport);

                    if (OrderRejectionArrived != null)
                    {
                        OrderRejectionArrived(rejection);
                    }
                    break;

                case ExecType.TRADE:
                {
                    Execution execution = PopulateExecution(executionReport);
                    if (Logger.IsDebugEnabled)
                    {
                        Logger.Debug("Trade arrived : " + execution, _type.FullName, "OnMessage");
                    }
                    if (ExecutionArrived != null)
                    {
                        ExecutionArrived(execution);
                    }
                    break;
                }
                }
            }
            catch (Exception exception)
            {
                Logger.Error(exception.ToString(), _type.FullName, "OnMessage");
            }
        }