Exemplo n.º 1
0
        /// <summary>
        /// Makes an execution object
        /// </summary>
        /// <param name="executionReport"></param>
        /// <returns></returns>
        private Execution PopulateExecution(QuickFix.FIX42.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.ExecType.getValue() == ExecType.FILL
                        ? Constants.ExecutionType.Fill
                        : Constants.ExecutionType.Partial,
                ExecutionId           = executionReport.ExecID.getValue(),
                ExecutionPrice        = Convert.ToDecimal(executionReport.AvgPx.getValue(), CultureInfo.InvariantCulture),
                ExecutionSize         = Convert.ToInt32(executionReport.LastShares.getValue()),
                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),
                OrderTif  = FixCommon.Converter.ConvertTif.GetLocalValue(executionReport.TimeInForce.getValue())
            };

            return(new Execution(fill, order));
        }
Exemplo n.º 2
0
 public void OnMessage(QuickFix.FIX42.ExecutionReport msg, QuickFix.SessionID s)
 {
     if (Fix42ExecReportEvent != null)
     {
         Fix42ExecReportEvent(msg);
     }
 }
Exemplo n.º 3
0
        public void HandleExecutionReport(QuickFix.FIX42.ExecutionReport msg)
        {
            try
            {
                string execId    = msg.ExecID.Obj;
                string transType = FixEnumTranslator.Translate(msg.ExecTransType);
                string execType  = FixEnumTranslator.Translate(msg.ExecType);

                Trace.WriteLine("EVM: Handling ExecutionReport: " + execId + " / " + transType + " / " + execType);

                ExecutionRecord exRec = new ExecutionRecord(
                    msg.ExecID.Obj,
                    msg.OrderID.Obj,
                    transType,
                    execType,
                    msg.Symbol.Obj,
                    FixEnumTranslator.Translate(msg.Side));

                SmartDispatcher.Invoke(new Action <ExecutionRecord>(AddExecution), exRec);
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.ToString());
            }
        }
Exemplo n.º 4
0
        //public void OnMessage(QuickFix.FIX42.SpreadMultiLegOrderSingle message, SessionID s)
        //{
        //    var noMdEntries = message.NoLegs.getValue();
        //    var group = new QuickFix.FIX42.SpreadMultiLegOrderSingle.NoLegsGroup();
        //    SendNewExecutionReport(message, s, noMdEntries, group);
        //    Thread.Sleep(100);
        //    SendFilledExecutionReport(message, s, noMdEntries, group);
        //}

        //private void SendNewExecutionReport(QuickFix.FIX42.SpreadMultiLegOrderSingle message, SessionID s, int noMdEntries, QuickFix.FIX42.SpreadMultiLegOrderSingle.NoLegsGroup group)
        //{
        //    Symbol symbol = new Symbol("L");
        //    Side side = new Side('L');
        //    OrdType ordType = message.OrdType;

        //    QuickFix.FIX42.ExecutionReport exReport = new QuickFix.FIX42.ExecutionReport(
        //            new OrderID(GenOrderID()),
        //            new ExecID(""),
        //            new ExecTransType(ExecTransType.NEW),
        //            new ExecType(ExecType.NEW),
        //            new OrdStatus(OrdStatus.NEW),
        //            symbol,
        //            side,
        //            new LeavesQty(0),
        //            new CumQty(0),
        //            new AvgPx(0));


        //    exReport.Set(message.ClOrdID);
        //    exReport.Set(message.TimeInForce);

        //    if (message.IsSetAccount())
        //        exReport.SetField(message.Account);

        //    for (int i = 1; i <= noMdEntries; i++)
        //    {
        //        var n = (QuickFix.FIX42.SpreadMultiLegOrderSingle.NoLegsGroup)message.GetGroup(i, group);

        //        var Exgroup = new QuickFix.FIX42.ExecutionReport.NoLegsGroup();

        //        Exgroup.LegOrderQty = new LegOrderQty(n.LegOrderQty.getValue());
        //        Exgroup.LegPrice = new LegPrice(n.LegPrice.getValue());
        //        Exgroup.LegSecurityID = new LegSecurityID(n.LegSecurityID.getValue());
        //        Exgroup.LegProduct = new LegProduct(n.LegProduct.getValue());
        //        message.AddGroup(Exgroup);
        //    }
        //    try
        //    {
        //        Session.SendToTarget(exReport, s);
        //    }
        //    catch (SessionNotFound ex)
        //    {
        //        Console.WriteLine("==session not found exception!==");
        //        Console.WriteLine(ex.ToString());
        //    }
        //    catch (Exception ex)
        //    {
        //        Console.WriteLine(ex.ToString());
        //    }

        //}

        //private void SendFilledExecutionReport(QuickFix.FIX42.SpreadMultiLegOrderSingle message, SessionID s, int noMdEntries, QuickFix.FIX42.SpreadMultiLegOrderSingle.NoLegsGroup group)
        //{
        //    for (int i = 1; i <= noMdEntries; i++)
        //    {
        //        var n = (QuickFix.FIX42.SpreadMultiLegOrderSingle.NoLegsGroup)message.GetGroup(i, group);
        //        SecurityID security = new SecurityID(n.LegSecurityID.getValue());
        //        Symbol symbol = new Symbol(n.LegSymbol.getValue());

        //        Side side = new Side(n.IsSetLegSide() ? n.LegSide.getValue() : 'B');
        //        OrdType ordType = message.OrdType;
        //        OrderQty orderQty = new OrderQty(n.LegOrderQty.getValue());
        //        ClOrdID clOrdID = message.ClOrdID;
        //        Price price = new Price(DEFAULT_MARKET_PRICE);
        //        TimeInForce tm = message.TimeInForce;
        //        switch (ordType.getValue())
        //        {
        //            case OrdType.LIMIT:
        //                price = new Price(n.LegPrice.getValue());
        //                if (price.Obj == 0)
        //                    throw new IncorrectTagValue(price.Tag);
        //                break;
        //            case OrdType.MARKET:
        //                break;
        //            default:
        //                throw new IncorrectTagValue(ordType.Tag);
        //        }

        //        QuickFix.FIX42.ExecutionReport exReport = new QuickFix.FIX42.ExecutionReport(
        //            new OrderID(GenOrderID()),
        //            new ExecID(DateTime.Now.ToString("yyyyMMddHHmmss") + GenExecID()),
        //            new ExecTransType(ExecTransType.NEW),
        //            new ExecType(ExecType.FILL),
        //            new OrdStatus(OrdStatus.FILLED),
        //            symbol,
        //            side,
        //            new LeavesQty(0),
        //            new CumQty(orderQty.getValue()),
        //            new AvgPx(price.getValue()));

        //        exReport.Set(security);
        //        exReport.Set(clOrdID);
        //        exReport.Set(orderQty);
        //        exReport.Set(new LastShares(orderQty.getValue()));
        //        exReport.Set(new LastPx(price.getValue()));
        //        exReport.Set(message.TimeInForce);
        //        if (message.IsSetAccount())
        //            exReport.SetField(message.Account);

        //        try
        //        {
        //            Session.SendToTarget(exReport, s);
        //        }
        //        catch (SessionNotFound ex)
        //        {
        //            Console.WriteLine("==session not found exception!==");
        //            Console.WriteLine(ex.ToString());
        //        }
        //        catch (Exception ex)
        //        {
        //            Console.WriteLine(ex.ToString());
        //        }
        //    }
        //}

        public void OnMessage(QuickFix.FIX42.NewOrderSingle n, SessionID s)
        {
            Symbol   symbol   = n.Symbol;
            Side     side     = n.Side;
            OrdType  ordType  = n.OrdType;
            OrderQty orderQty = n.OrderQty;
            ClOrdID  clOrdID  = n.ClOrdID;
            Price    price    = new Price(DEFAULT_MARKET_PRICE);

            switch (ordType.getValue())
            {
            case OrdType.LIMIT:
                price = n.Price;
                if (price.Obj == 0)
                {
                    throw new IncorrectTagValue(price.Tag);
                }
                break;

            case OrdType.MARKET: break;

            default: throw new IncorrectTagValue(ordType.Tag);
            }

            QuickFix.FIX42.ExecutionReport exReport = new QuickFix.FIX42.ExecutionReport(
                new OrderID(GenOrderID()),
                new ExecID(GenExecID()),
                new ExecTransType(ExecTransType.NEW),
                new ExecType(ExecType.FILL),
                new OrdStatus(OrdStatus.FILLED),
                symbol,
                side,
                new LeavesQty(0),
                new CumQty(orderQty.getValue()),
                new AvgPx(price.getValue()));

            exReport.Set(clOrdID);
            exReport.Set(orderQty);
            exReport.Set(new LastShares(orderQty.getValue()));
            exReport.Set(new LastPx(price.getValue()));

            if (n.IsSetAccount())
            {
                exReport.SetField(n.Account);
            }

            try
            {
                Session.SendToTarget(exReport, s);
            }
            catch (SessionNotFound ex)
            {
                Console.WriteLine("==session not found exception!==");
                Console.WriteLine(ex.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Exemplo n.º 5
0
        public void OnMessage(QuickFix.FIX42.ExecutionReport m, SessionID s)
        {
            Console.WriteLine("Received execution report");

            if (Fix42ExecReportEvent != null)
            {
                Fix42ExecReportEvent(m);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Extracts the rejection details from the incoming message
        /// </summary>
        /// <param name="executionReport"></param>
        /// <returns></returns>
        private Rejection ExtractOrderRejection(QuickFix.FIX42.ExecutionReport executionReport)
        {
            Rejection rejection = new Rejection(new Security()
            {
                Symbol = executionReport.Symbol.getValue()
            }, _provider,
                                                executionReport.TransactTime.getValue());

            rejection.OrderId        = executionReport.OrderID.getValue();
            rejection.RejectioReason = executionReport.OrdRejReason.getValue().ToString();

            return(rejection);
        }
Exemplo n.º 7
0
        public void OneIncomingExecution()
        {
            UnitTestContext context = new UnitTestContext();

            context.Login();

            ExecutionViewModel vm = new ExecutionViewModel(context.App);

            QuickFix.FIX42.ExecutionReport ex = CreateExReport("order1", "exec1", QuickFix.Fields.ExecTransType.NEW,
                                                               QuickFix.Fields.ExecType.NEW, QuickFix.Fields.OrdStatus.NEW, "IBM", QuickFix.Fields.Side.BUY, 1.23m, 4.56m, 7.89m);

            context.App.FromApp(ex, context.Session.SessionID);

            Assert.AreEqual(1, vm.Executions.Count);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Makes an order object
        /// </summary>
        /// <param name="executionReport"></param>
        /// <returns></returns>
        private Order PopulateOder(QuickFix.FIX42.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),
                OrderTif  = FixCommon.Converter.ConvertTif.GetLocalValue(executionReport.TimeInForce.getValue())
            };

            return(order);
        }
 private void SendExecReport(QuickFix.FIX42.ExecutionReport exReport)
 {
     try
     {
         _session.Send(exReport);
     }
     catch (SessionNotFound ex)
     {
         Console.WriteLine("==session not found exception!==");
         Console.WriteLine(ex.ToString());
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
     }
 }
Exemplo n.º 10
0
        public void FromApp(QuickFix.Message msg, SessionID sessionID)
        {
            logMe("\r\n \r\n" + "FromApp :" + msg.ToString());

            if (msg is QuickFix.FIX42.ExecutionReport)
            {
                QuickFix.FIX42.ExecutionReport er = (QuickFix.FIX42.ExecutionReport)msg;

                logMe("\r\n \r\n" + "Got execution Report - ExecType = " + er.ExecType.getValue());

                if (er.ExecType.getValue() == ExecType.FILL)
                {
                    logMe("\r\n \r\n" + "FromApp : order Filled");
                }
            }
        }
        private void SendAck(NewOrderSingle newOrderSingle)
        {
            var      exReport = new QuickFix.FIX42.ExecutionReport();
            OrderQty orderQty = newOrderSingle.OrderQty;

            exReport.CopyFromOrder(newOrderSingle);
            exReport.Set(new OrderID(GenOrderID()));
            exReport.Set(new ExecID(GenExecID()));
            exReport.Set(new ExecTransType(ExecTransType.NEW));
            exReport.Set(new ExecType(ExecType.NEW));
            exReport.Set(new OrdStatus(OrdStatus.NEW));
            exReport.Set(new LeavesQty(orderQty.getValue()));
            exReport.Set(new CumQty(0));
            exReport.Set(new AvgPx(0));

            SendExecReport(exReport);
        }
Exemplo n.º 12
0
        public void HandleExecutionReport(QuickFix.FIX42.ExecutionReport msg)
        {
            try
            {
                string execId    = msg.ExecID.Obj;
                string transType = FixEnumTranslator.Translate(msg.ExecTransType);
                string execType  = FixEnumTranslator.Translate(msg.ExecType);

                Trace.WriteLine("EVM: Handling ExecutionReport: " + execId + " / " + transType + " / " + execType);

                String securityType = "";
                if (msg.IsSetField(167))
                {
                    securityType = FixEnumTranslator.Translate(msg.SecurityType);
                }

                String putOrCall = "";
                if (msg.IsSetField(201))
                {
                    putOrCall = FixEnumTranslator.Translate(msg.PutOrCall);
                }

                decimal strikePrice = 0;
                if (msg.IsSetField(202))
                {
                    strikePrice = msg.StrikePrice.Obj;
                }

                ExecutionRecord exRec = new ExecutionRecord(
                    msg.ExecID.Obj,
                    msg.OrderID.Obj,
                    transType,
                    execType,
                    msg.Symbol.Obj,
                    FixEnumTranslator.Translate(msg.Side),
                    securityType,
                    putOrCall,
                    strikePrice);

                SmartDispatcher.Invoke(new Action <ExecutionRecord>(AddExecution), exRec);
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.ToString());
            }
        }
        public void HandleExecutionReport(QuickFix.FIX42.ExecutionReport msg)
        {
            try
            {
                if (msg.IsSetField(11) && msg.ClOrdID != null)
                {
                    string clOrdId = msg.ClOrdID.Obj;


                    string status = FixEnumTranslator.Translate(msg.OrdStatus);

                    //Trace.WriteLine("OVM: Handling ExecutionReport: " + clOrdId + " / " + status);

                    lock (_ordersLock)
                    {
                        foreach (OrderRecord r in Orders)
                        {
                            if (r.ClOrdID == clOrdId)
                            {
                                r.Status = status;
                                if (msg.IsSetLastPx())
                                {
                                    r.Price = msg.LastPx.Obj;
                                }
                                if (msg.IsSetOrderID())
                                {
                                    r.OrderID = msg.OrderID.Obj;
                                }

                                return;
                            }
                        }
                    }

                    //Trace.WriteLine("OVM: No order corresponds to ClOrdID '" + clOrdId + "'");
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.ToString());
            }
        }
Exemplo n.º 14
0
 private void OnExecutionReport(QuickFix.FIX42.ExecutionReport executionReport)
 {
     lock (m_OpenOrderIds) {
         m_NumOfExeReportsReceived++;
         bool flag = m_OpenOrderIds.Remove(executionReport.OrderID.getValue());
         if (!flag)
         {
             Console.WriteLine("Unexpecpted OrderID. Something must be wrong.");
         }
         if (m_OpenOrderIds.Count == 0)
         {
             m_Stopwatch.Stop();
             Console.WriteLine("\nTotal Time in ms: " + m_Stopwatch.ElapsedMilliseconds);
             Console.WriteLine("Average Time in ms: " + (double)m_Stopwatch.ElapsedMilliseconds / (double)m_NumOfExeReportsReceived);
             Console.WriteLine("Execution report received: " + m_NumOfExeReportsReceived);
             m_OpenOrderIds.Clear();
             m_NumOfExeReportsReceived = 0;
         }
     }
 }
Exemplo n.º 15
0
        public void OrderUpdate()
        {
            UnitTestContext context = new UnitTestContext();

            context.Login();

            OrderViewModel vm = new OrderViewModel(context.App, new FIXApplication.NullFixStrategy());

            // send an order with default arguments
            vm.SendBuyCommand.Execute(null);
            Assert.AreEqual(1, context.Session.MsgLookup[QuickFix.FIX42.NewOrderSingle.MsgType].Count);
            QuickFix.FIX42.NewOrderSingle msg = context.Session.MsgLookup[QuickFix.FIX42.NewOrderSingle.MsgType][0] as QuickFix.FIX42.NewOrderSingle;

            // verify grid content (redundant with earlier tests, but whatever)
            Assert.AreEqual(1, vm.Orders.Count);
            OrderRecord or = vm.Orders.First();

            Assert.AreEqual("IBM", or.Symbol);
            Assert.AreEqual(-1, or.Price);
            Assert.AreEqual("Market", or.OrdType);
            Assert.AreEqual("Buy", or.Side);
            Assert.AreEqual("New", or.Status);

            // send an execution report that will update the grid
            QuickFix.FIX42.ExecutionReport r = CreateExReport(
                or.ClOrdID, "foo", QuickFix.Fields.ExecTransType.NEW, QuickFix.Fields.ExecType.FILL,
                QuickFix.Fields.OrdStatus.FILLED, "IBM", QuickFix.Fields.Side.BUY, 0, 0, 0);
            r.LastPx  = new QuickFix.Fields.LastPx(999m);
            r.ClOrdID = new QuickFix.Fields.ClOrdID(msg.ClOrdID.Obj);

            context.App.FromApp(r, context.Session.SessionID);

            // check that it got changed
            Assert.AreEqual(1, vm.Orders.Count);
            Assert.AreEqual(999, or.Price);
            Assert.AreEqual("Filled", or.Status);
        }
Exemplo n.º 16
0
        public void ManyExecutions()
        {
            UnitTestContext context = new UnitTestContext();

            context.Login();

            ExecutionViewModel vm = new ExecutionViewModel(context.App);

            QuickFix.FIX42.ExecutionReport ex1 = CreateExReport("order1", "exec1", QuickFix.Fields.ExecTransType.NEW,
                                                                QuickFix.Fields.ExecType.NEW, QuickFix.Fields.OrdStatus.NEW, "IBM", QuickFix.Fields.Side.BUY, 1.23m, 4.56m, 7.89m);
            QuickFix.FIX42.ExecutionReport ex2 = CreateExReport("order1", "exec1", QuickFix.Fields.ExecTransType.CORRECT,
                                                                QuickFix.Fields.ExecType.NEW, QuickFix.Fields.OrdStatus.NEW, "ABC", QuickFix.Fields.Side.SELL, 1.23m, 4.56m, 7.89m);
            QuickFix.FIX42.ExecutionReport ex3 = CreateExReport("order1", "exec1", QuickFix.Fields.ExecTransType.CANCEL,
                                                                QuickFix.Fields.ExecType.NEW, QuickFix.Fields.OrdStatus.NEW, "XYZ", QuickFix.Fields.Side.BUY, 1.23m, 4.56m, 7.89m);

            context.App.FromApp(ex1, context.Session.SessionID);
            context.App.FromApp(ex2, context.Session.SessionID);
            context.App.FromApp(ex3, context.Session.SessionID);

            Assert.AreEqual(3, vm.Executions.Count);

            Assert.AreEqual("order1", vm.Executions[0].OrderID);
            Assert.AreEqual("New", vm.Executions[0].ExecTransType);
            Assert.AreEqual("IBM", vm.Executions[0].Symbol);
            Assert.AreEqual("Buy", vm.Executions[0].Side);

            Assert.AreEqual("order1", vm.Executions[1].OrderID);
            Assert.AreEqual("Correct", vm.Executions[1].ExecTransType);
            Assert.AreEqual("ABC", vm.Executions[1].Symbol);
            Assert.AreEqual("Sell", vm.Executions[1].Side);

            Assert.AreEqual("order1", vm.Executions[2].OrderID);
            Assert.AreEqual("Cancel", vm.Executions[2].ExecTransType);
            Assert.AreEqual("XYZ", vm.Executions[2].Symbol);
            Assert.AreEqual("Buy", vm.Executions[2].Side);
        }
Exemplo n.º 17
0
        public void OnMessage(QuickFix.FIX42.NewOrderSingle n, SessionID s)
        {
            Symbol symbol = n.Symbol;
            Side side = n.Side;
            OrdType ordType = n.OrdType;
            OrderQty orderQty = n.OrderQty;
            ClOrdID clOrdID = n.ClOrdID;
            Price price = new Price(DEFAULT_MARKET_PRICE);

            switch (ordType.getValue())
            {
                case OrdType.LIMIT:
                    price = n.Price;
                    if (price.Obj == 0)
                        throw new IncorrectTagValue(price.Tag);
                    break;
                case OrdType.MARKET: break;
                default: throw new IncorrectTagValue(ordType.Tag);
            }

            QuickFix.FIX42.ExecutionReport exReport = new QuickFix.FIX42.ExecutionReport(
                new OrderID(GenOrderID()),
                new ExecID(GenExecID()),
                new ExecTransType(ExecTransType.NEW),
                new ExecType(ExecType.FILL),
                new OrdStatus(OrdStatus.FILLED),
                symbol,
                side,
                new LeavesQty(0),
                new CumQty(orderQty.getValue()),
                new AvgPx(price.getValue()));

            exReport.Set(clOrdID);
            exReport.Set(orderQty);
            exReport.Set(new LastShares(orderQty.getValue()));
            exReport.Set(new LastPx(price.getValue()));

            if (n.IsSetAccount())
                exReport.SetField(n.Account);

            try
            {
                Session.SendToTarget(exReport, s);
            }
            catch (SessionNotFound ex)
            {
                Console.WriteLine("==session not found exception!==");
                Console.WriteLine(ex.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Exemplo n.º 18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="executionReport">Execution report</param>
        /// <param name="sessionId">Session ID</param>
        private void OnMessage(QuickFix.FIX42.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 '1':
                {
                    Execution execution = PopulateExecution(executionReport);
                    if (Logger.IsDebugEnabled)
                    {
                        Logger.Debug("Trade arrived : " + execution, _type.FullName, "OnMessage");
                    }
                    if (ExecutionArrived != null)
                    {
                        ExecutionArrived(execution);
                    }
                    break;
                }

                case '2':
                {
                    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");
            }
        }
Exemplo n.º 19
0
 private void OnMessage(QuickFix.FIX42.NewOrderSingle n, SessionID s)
 {
     QuickFix.FIX42.ExecutionReport executionReport = new QuickFix.FIX42.ExecutionReport(new OrderID(n.ClOrdID.getValue()), new ExecID(Guid.NewGuid().ToString()), new ExecTransType(ExecTransType.NEW), new ExecType(ExecType.NEW), new OrdStatus(OrdStatus.NEW), n.Symbol, n.Side, new LeavesQty(n.OrderQty.getValue()), new CumQty(0), new AvgPx());
     Session.SendToTarget(executionReport, s);
 }
Exemplo n.º 20
0
        public static QuickFix.FIX42.ExecutionReport Fix42Rejection2ExecutionReport(QuickFix.Message msgReject, QuickFix.Message msgOri)
        {
            try
            {
                QuickFix.FIX42.ExecutionReport er = new QuickFix.FIX42.ExecutionReport();
                if (msgOri.IsSetField(Tags.OrderID))
                {
                    er.SetField(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.IsSetField(Tags.NoPartyIDs)? msgOri.GetInt(Tags.NoPartyIDs): 0;
                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 (msgReject.IsSetField(Tags.Text))
                {
                    er.Set(new Text(msgReject.GetField(Tags.Text)));
                }
                if (msgOri.IsSetField(Tags.Memo))
                {
                    er.SetField(new Memo(msgOri.GetString(Tags.Memo)));
                }

                // Validacao da tag ExecTransType. Para rejeicao, atribuindo default STATUS
                er.Set(new ExecTransType(ExecTransType.STATUS));

                return(er);
            }
            catch (Exception ex)
            {
                logger.Error("Fix44Rejection2ExecutionReport(): " + ex.Message, ex);
                return(null);
            }
        }
Exemplo n.º 21
0
        protected void SendExecutionReport(OrderFixBridge order, string symbol, double execQty, double execPrice, string text)
        {
            if (order == null)
            {
                throw new Exception("[QuickFixApp.SendExecutionReport] OrderFixBridge order is null ");
            }
            IOrder o = order.Order;

            if (o == null)
            {
                throw new Exception("[QuickFixApp.SendExecutionReport] IOrder is null ");
            }
            if (string.IsNullOrEmpty(symbol))
            {
                throw new Exception("[QuickFixApp.SendExecutionReport] symbol is empty");
            }

            QuickFix.SessionID session = order.OrderSessionID;
            if (session == null)
            {
                throw new Exception("[QuickFixApp.SendExecutionReport] session is null ");
            }

            QuickFix.FIX42.ExecutionReport msg = new QuickFix.FIX42.ExecutionReport();
            msg.OrderID       = new QuickFix.Fields.OrderID(Helper.GetUniqueID("EXECID"));
            msg.HandlInst     = new QuickFix.Fields.HandlInst(QuickFix.Fields.HandlInst.AUTOMATED_EXECUTION_ORDER_PRIVATE_NO_BROKER_INTERVENTION);
            msg.Symbol        = new QuickFix.Fields.Symbol(symbol);
            msg.Side          = Converter.c(o.OrderAction);
            msg.LeavesQty     = new QuickFix.Fields.LeavesQty(Convert.ToDecimal(Math.Max(0, o.Quantity - o.Filled)));
            msg.CumQty        = new QuickFix.Fields.CumQty(Convert.ToDecimal(o.Filled));
            msg.AvgPx         = new QuickFix.Fields.AvgPx(Convert.ToDecimal(o.AvgFillPrice));
            msg.TransactTime  = new QuickFix.Fields.TransactTime(o.Time, true);
            msg.Text          = new QuickFix.Fields.Text(text);
            msg.ExecTransType = new QuickFix.Fields.ExecTransType(QuickFix.Fields.ExecTransType.NEW);

            switch (o.OrderState)
            {
            // pending : ignored
            case OrderState.Accepted:
            case OrderState.PendingChange:
            case OrderState.PendingSubmit:
            case OrderState.PendingCancel:
                return;

            case OrderState.Working:
                msg.OrdStatus = new QuickFix.Fields.OrdStatus(QuickFix.Fields.OrdStatus.NEW);

                msg.ExecID   = new QuickFix.Fields.ExecID(Helper.GetUniqueID("NEW"));
                msg.ExecType = new QuickFix.Fields.ExecType(QuickFix.Fields.ExecType.NEW);

                break;

            case OrderState.Cancelled:
                msg.OrdStatus = new QuickFix.Fields.OrdStatus(QuickFix.Fields.OrdStatus.CANCELED);
                msg.ExecID    = new QuickFix.Fields.ExecID(Helper.GetUniqueID("CANCELED"));
                msg.ExecType  = new QuickFix.Fields.ExecType(QuickFix.Fields.ExecType.CANCELED);

                break;

            case OrderState.Filled:
            case OrderState.PartFilled:

                if (double.IsNaN(execQty))
                {
                    return;
                }
                if (double.IsNaN(execPrice))
                {
                    return;
                }

                bool full = o.OrderState == OrderState.Filled;

                msg.OrdStatus  = new QuickFix.Fields.OrdStatus(full ? QuickFix.Fields.OrdStatus.FILLED : QuickFix.Fields.OrdStatus.PARTIALLY_FILLED);
                msg.ExecID     = new QuickFix.Fields.ExecID(Helper.GetUniqueID("EXEC"));
                msg.ExecType   = new QuickFix.Fields.ExecType(full ? QuickFix.Fields.ExecType.FILL : QuickFix.Fields.ExecType.PARTIAL_FILL);
                msg.LastShares = new QuickFix.Fields.LastShares(Convert.ToDecimal(execQty));
                msg.LastPx     = new QuickFix.Fields.LastPx(Convert.ToDecimal(execPrice));

                break;

            case OrderState.Rejected:

                msg.OrdStatus   = new QuickFix.Fields.OrdStatus(QuickFix.Fields.OrdStatus.REJECTED);
                msg.ExecType    = new QuickFix.Fields.ExecType(QuickFix.Fields.ExecType.REJECTED);
                msg.OrigClOrdID = new QuickFix.Fields.OrigClOrdID(order.QuickFixId);
                msg.ExecID      = new QuickFix.Fields.ExecID(Helper.GetUniqueID("REJ"));
                break;


            case OrderState.Unknown:
                throw new Exception("[QuickFixApp.SendExecutionReport] IOrder should not have unknown status at this point !");
            }

            QuickFix.Session.SendToTarget(msg, session);
        }
Exemplo n.º 22
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);
            }
        }
        private void SendExecReport(NewOrderSingle newOrderSingle, IExecutionEngineSettings settings)
        {
            OrdType ordType = newOrderSingle.OrdType;
            Price   price   = new Price(10);

            switch (ordType.getValue())
            {
            case OrdType.LIMIT:
                price = newOrderSingle.Price;
                if (price.Obj == 0)
                {
                    throw new IncorrectTagValue(price.Tag);
                }
                break;

            case OrdType.MARKET:
                break;

            default:
                throw new IncorrectTagValue(ordType.Tag);
            }

            OrderQty orderQty = newOrderSingle.OrderQty;
            var      exReport = new QuickFix.FIX42.ExecutionReport();

            exReport.CopyFromOrder(newOrderSingle);
            exReport.Set(new ExecTransType(ExecTransType.NEW));
            exReport.Set(new ExecType(ExecType.FILL));
            exReport.Set(new LastPx(price.getValue()));
            exReport.Set(new AvgPx(price.getValue()));

            decimal qtyPerSlice = orderQty.getValue() *
                                  ((settings.EachFillPercentange ?? 100) / 100m);

            decimal leaves = orderQty.getValue();
            decimal cumQty = 0;

            while (leaves != 0)
            {
                if (leaves <= qtyPerSlice)
                {
                    leaves      = 0;
                    qtyPerSlice = leaves;
                    exReport.Set(new OrdStatus(OrdStatus.FILLED));
                }
                else
                {
                    leaves -= qtyPerSlice;
                    exReport.Set(new OrdStatus(OrdStatus.PARTIALLY_FILLED));
                }

                cumQty += qtyPerSlice;
                exReport.Set(new OrderID(GenOrderID()));
                exReport.Set(new ExecID(GenExecID()));

                exReport.Set(new LeavesQty(leaves));
                exReport.Set(new CumQty(cumQty));

                exReport.Set(new LastShares(qtyPerSlice));
                SendExecReport(exReport);
                Thread.Sleep(Convert.ToInt32(settings.SecondsBetweenFills * 1000));
            }
        }
Exemplo n.º 24
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);
            }
        }
Exemplo n.º 25
0
 private void OnMessage(QuickFix.FIX42.NewOrderSingle n, SessionID s)
 {
     QuickFix.FIX42.ExecutionReport executionReport = new QuickFix.FIX42.ExecutionReport(new OrderID(n.ClOrdID.getValue()), new ExecID(Guid.NewGuid().ToString()), new ExecTransType(ExecTransType.NEW), new ExecType(ExecType.NEW), new OrdStatus(OrdStatus.NEW), n.Symbol, n.Side, new LeavesQty(n.OrderQty.getValue()), new CumQty(0), new AvgPx());
     Session.SendToTarget(executionReport, s);
 }
Exemplo n.º 26
0
        protected void SendExecutionReport(OrderFixBridge order, string symbol, double execQty, double execPrice, string text)
        {
            if (order == null) throw new Exception("[QuickFixApp.SendExecutionReport] OrderFixBridge order is null ");
            IOrder o = order.Order;

            if (o == null) throw new Exception("[QuickFixApp.SendExecutionReport] IOrder is null ");
            if (string.IsNullOrEmpty(symbol)) throw new Exception("[QuickFixApp.SendExecutionReport] symbol is empty");

            QuickFix.SessionID session = order.OrderSessionID;
            if (session == null) throw new Exception("[QuickFixApp.SendExecutionReport] session is null ");

            QuickFix.FIX42.ExecutionReport msg = new QuickFix.FIX42.ExecutionReport();
            msg.OrderID = new QuickFix.Fields.OrderID(Helper.GetUniqueID("EXECID"));
            msg.HandlInst = new QuickFix.Fields.HandlInst(QuickFix.Fields.HandlInst.AUTOMATED_EXECUTION_ORDER_PRIVATE_NO_BROKER_INTERVENTION);
            msg.Symbol = new QuickFix.Fields.Symbol(symbol);
            msg.Side = Converter.c(o.OrderAction);
            msg.LeavesQty = new QuickFix.Fields.LeavesQty(Convert.ToDecimal(Math.Max(0,o.Quantity-o.Filled)));
            msg.CumQty = new QuickFix.Fields.CumQty(Convert.ToDecimal(o.Filled));
            msg.AvgPx = new QuickFix.Fields.AvgPx(Convert.ToDecimal(o.AvgFillPrice));
            msg.TransactTime = new QuickFix.Fields.TransactTime(o.Time, true);
            msg.Text = new QuickFix.Fields.Text(text);
            msg.ExecTransType = new QuickFix.Fields.ExecTransType(QuickFix.Fields.ExecTransType.NEW);

            switch (o.OrderState)
            {
                     // pending : ignored
                case OrderState.Accepted:
                case OrderState.PendingChange:
                case OrderState.PendingSubmit:
                case OrderState.PendingCancel:
                    return;

                case OrderState.Working:
                    msg.OrdStatus = new QuickFix.Fields.OrdStatus(QuickFix.Fields.OrdStatus.NEW);

                    msg.ExecID = new QuickFix.Fields.ExecID(Helper.GetUniqueID("NEW"));
                    msg.ExecType = new QuickFix.Fields.ExecType(QuickFix.Fields.ExecType.NEW);

                    break;

                case OrderState.Cancelled:
                    msg.OrdStatus = new QuickFix.Fields.OrdStatus(QuickFix.Fields.OrdStatus.CANCELED);
                    msg.ExecID = new QuickFix.Fields.ExecID(Helper.GetUniqueID("CANCELED"));
                    msg.ExecType = new QuickFix.Fields.ExecType(QuickFix.Fields.ExecType.CANCELED);

                    break;

                case OrderState.Filled:
                case OrderState.PartFilled:

                    if (double.IsNaN(execQty)) return;
                    if (double.IsNaN(execPrice)) return;

                    bool full = o.OrderState == OrderState.Filled;

                    msg.OrdStatus = new QuickFix.Fields.OrdStatus(full ? QuickFix.Fields.OrdStatus.FILLED : QuickFix.Fields.OrdStatus.PARTIALLY_FILLED);
                    msg.ExecID = new QuickFix.Fields.ExecID(Helper.GetUniqueID("EXEC"));
                    msg.ExecType = new QuickFix.Fields.ExecType(full ? QuickFix.Fields.ExecType.FILL : QuickFix.Fields.ExecType.PARTIAL_FILL);
                    msg.LastShares = new QuickFix.Fields.LastShares(Convert.ToDecimal(execQty));
                    msg.LastPx = new QuickFix.Fields.LastPx(Convert.ToDecimal(execPrice));

                    break;

                case OrderState.Rejected:

                    msg.OrdStatus = new QuickFix.Fields.OrdStatus(QuickFix.Fields.OrdStatus.REJECTED);
                    msg.ExecType = new QuickFix.Fields.ExecType(QuickFix.Fields.ExecType.REJECTED);
                    msg.OrigClOrdID = new QuickFix.Fields.OrigClOrdID(order.QuickFixId);
                    msg.ExecID = new QuickFix.Fields.ExecID(Helper.GetUniqueID("REJ"));
                    break;

                case OrderState.Unknown:
                    throw new Exception("[QuickFixApp.SendExecutionReport] IOrder should not have unknown status at this point !");
            }

            QuickFix.Session.SendToTarget(msg, session);
        }
Exemplo n.º 27
0
 public void OnMessage(QuickFix.FIX42.ExecutionReport m, SessionID s)
 {
     Console.WriteLine("Received execution report");
 }