//Here we will process the rejected messages and see if that's ok or not
        protected void ProcessReject(object param)
        {
            try
            {
                lock (TimeoutOrders)
                {
                    Wrapper rejectWrapper = (Wrapper)param;

                    string key  = (string)rejectWrapper.GetField(RejectFields.KEY);
                    string text = (string)rejectWrapper.GetField(RejectFields.Text);

                    if (TimeoutOrders.ContainsKey(key))
                    {
                        TimeoutOrders.Remove(key);
                    }

                    //Implement rejects
                    if (OrdersSent.ContainsKey(key))
                    {
                        DoLog(string.Format("<{0}>-Received reject message for Cl. Order Id {1}:{2}", Configuration.Name, key, text), Constants.MessageType.AssertFailed);
                        OrdersSent.Remove(key);
                    }
                }
            }
            catch (Exception ex)
            {
                DoLog(string.Format("{0}-Critical error processing a reject:{1}", Configuration.Name, ex.Message), Constants.MessageType.Error);
            }
        }
Example #2
0
        public void RunTestsThread()
        {
            try
            {
                //1- Send orders and get ready to validate counters
                DoLog(string.Format("Sending full regular order @{0}", Configuration.Name), Constants.MessageType.Information);
                Order           fullOrder1       = OrderBuilder.BuildFullOrder();
                NewOrderWrapper fullOrderWrapper = new NewOrderWrapper(fullOrder1, Configuration);
                OrdersSent.Add(fullOrder1.ClOrdId, fullOrder1);
                TimeoutOrders.Add(fullOrder1.ClOrdId, DateTime.Now);
                DoPublishMessage(fullOrderWrapper);

                Order           fullOrder2        = OrderBuilder.BuildFullOrder();
                NewOrderWrapper fullOrderWrapper2 = new NewOrderWrapper(fullOrder2, Configuration);
                OrdersSent.Add(fullOrder2.ClOrdId, fullOrder1);
                TimeoutOrders.Add(fullOrder2.ClOrdId, DateTime.Now);
                DoPublishMessage(fullOrderWrapper2);

                Order           fullOrder3        = OrderBuilder.BuildFullOrder();
                NewOrderWrapper fullOrderWrapper3 = new NewOrderWrapper(fullOrder3, Configuration);
                OrdersSent.Add(fullOrder3.ClOrdId, fullOrder3);
                TimeoutOrders.Add(fullOrder3.ClOrdId, DateTime.Now);
                DoPublishMessage(fullOrderWrapper3);
            }
            catch (Exception ex)
            {
                DoLog(string.Format("{0}-Critical error running tests:{1}", Configuration.Name, ex.Message), Constants.MessageType.Error);
            }
        }
Example #3
0
        //Here we will process the rejected messages and see if that's ok or not
        protected void ProcessReject(object param)
        {
            try
            {
                lock (TimeoutOrders)
                {
                    Wrapper rejectWrapper = (Wrapper)param;

                    string key  = (string)rejectWrapper.GetField(RejectFields.KEY);
                    string text = (string)rejectWrapper.GetField(RejectFields.Text);

                    if (TimeoutOrders.ContainsKey(key))
                    {
                        TimeoutOrders.Remove(key);
                    }

                    //Implement rejects

                    if (OrdersSent.ContainsKey(key))
                    {
                        //Validar que el error es por Extra Tags
                    }
                }
            }
            catch (Exception ex)
            {
                DoLog(string.Format("{0}-Critical error processing a reject:{1}", Configuration.Name, ex.Message), Constants.MessageType.Error);
            }
        }
        protected void ProcessExecutionReport(object param)
        {
            try
            {
                lock (TimeoutOrders)
                {
                    Wrapper erWrapper = (Wrapper)param;

                    string key = (string)erWrapper.GetField(ExecutionReportFields.KEY);

                    string orderId   = (string)erWrapper.GetField(ExecutionReportFields.OrderID);
                    string clOrderId = (string)erWrapper.GetField(ExecutionReportFields.ClOrdID);

                    if (OrdersSent.ContainsKey(key) && LastProcessedCounter.ContainsKey(key))
                    {
                        DoLog(string.Format("<{0}>- Received order id {1} - cl order id {2}", Configuration.Name, orderId, clOrderId), Constants.MessageType.Information);

                        try
                        {
                            int counter     = Convert.ToInt32(erWrapper.GetField(ExecutionReportFields.Account));
                            int lastCounter = LastProcessedCounter[clOrderId];

                            //We validate that it's lower. No that it has a specific number
                            if (counter == Configuration.ExecutionReportsPerOrder && counter == (lastCounter + 1))
                            {
                                DoLog(string.Format("<{0}>- Received counter #{1} for cl. order id {2} which is the last counter and all the previous counter were received ok!. The count is ok!",
                                                    Configuration.Name, counter, clOrderId), Constants.MessageType.AssertOk);
                                ClearOrderTracking(clOrderId);
                            }
                            else
                            {
                                if (counter == (lastCounter + 1))
                                {
                                    LastProcessedCounter[clOrderId] = counter;
                                }
                                else
                                {
                                    DoLog(string.Format("<{0}>- Recevied counter #{1} and expected #{2} for cl. order id {3} . Wrong counter number!",
                                                        Configuration.Name, counter, lastCounter + 1, clOrderId), Constants.MessageType.AssertFailed);
                                    ClearOrderTracking(clOrderId);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            DoLog(string.Format("<{0}>- Received an order Id with a counter that doesn't seem to be an int value: {1}", Configuration.Name, erWrapper.GetField(ExecutionReportFields.Account)), Constants.MessageType.AssertFailed);
                            OrdersSent.Remove(clOrderId);
                        }
                    }
                    //This must be an order we don't manage or that we have already rejected so the counter is considered to be not working
                }
            }
            catch (Exception ex)
            {
                DoLog(string.Format("<{0}>-Critical error processing a execution report:{1}", Configuration.Name, ex.Message), Constants.MessageType.AssertFailed);
            }
        }
        public void RunTestsThread()
        {
            try
            {
                while (true)
                {
                    //1- Send orders and get ready to validate counters
                    DoLog(string.Format("Sending full regular order @{0}", Configuration.Name), Constants.MessageType.Information);
                    Order           fullOrder1       = OrderBuilder.BuildFullOrder();
                    NewOrderWrapper fullOrderWrapper = new NewOrderWrapper(fullOrder1, Configuration);
                    OrdersSent.Add(fullOrder1.ClOrdId, fullOrder1);
                    TimeoutOrders.Add(fullOrder1.ClOrdId, DateTime.Now);
                    LastProcessedCounter.Add(fullOrder1.ClOrdId, 0);
                    DoPublishMessage(fullOrderWrapper);

                    Thread.Sleep(1000 * Configuration.PauseBetweenOrdersInSeconds);//1 second
                }
            }
            catch (Exception ex)
            {
                DoLog(string.Format("{0}-Critical error running tests:{1}", Configuration.Name, ex.Message), Constants.MessageType.Error);
            }
        }
 private void ClearOrderTracking(string clOrderId)
 {
     TimeoutOrders.Remove(clOrderId);
     LastProcessedCounter.Remove(clOrderId);
     OrdersSent.Remove(clOrderId);
 }
Example #7
0
        protected void ProcessExecutionReport(object param)
        {
            try
            {
                lock (TimeoutOrders)
                {
                    Wrapper erWrapper = (Wrapper)param;

                    string key = (string)erWrapper.GetField(ExecutionReportFields.KEY);

                    string orderId   = (string)erWrapper.GetField(ExecutionReportFields.OrderID);
                    string clOrderId = (string)erWrapper.GetField(ExecutionReportFields.ClOrdID);


                    if (TimeoutOrders.ContainsKey(key))
                    {
                        TimeoutOrders.Remove(key);
                    }

                    if (OrdersSent.ContainsKey(key))
                    {
                        if (orderId.Contains("_"))
                        {
                            DoLog(string.Format("<{0}>- Received order id {1}", Configuration.Name, orderId), Constants.MessageType.AssertOk);

                            string strCount = orderId.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries)[1];


                            try
                            {
                                int count = Convert.ToInt32(strCount);

                                //We validate that it's lower. No that it has a specific number
                                if (LastProcessedCounter.HasValue && LastProcessedCounter.Value < count)
                                {
                                    DoLog(string.Format("<{0}>- Recevied an orderId counter {1} which is bigger than the number we had in memory. The count seems ok",
                                                        Configuration.Name, count, LastProcessedCounter.HasValue ? LastProcessedCounter.Value.ToString() : "-"), Constants.MessageType.AssertOk);
                                    LastProcessedCounter = count;
                                }
                                else
                                {
                                    if (LastProcessedCounter.HasValue)
                                    {
                                        DoLog(string.Format("<{0}>- Recevied an orderId counter {1} which is LOWER than the number we had in memory. What happened with the counter?",
                                                            Configuration.Name, count, LastProcessedCounter.HasValue ? LastProcessedCounter.Value.ToString() : "-"), Constants.MessageType.AssertFailed);

                                        OrdersSent.Remove(key);
                                    }
                                    else
                                    {
                                        LastProcessedCounter = count;
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                DoLog(string.Format("<{0}>- Received an order Id with a counter that doesn't seem to be an int value: {1}", Configuration.Name, strCount), Constants.MessageType.AssertFailed);
                                OrdersSent.Remove(key);
                            }
                        }
                        else
                        {
                            DoLog(string.Format("<{0}>- Received an order Id whose format doesn't match the exepected one: {1}", Configuration.Name, orderId), Constants.MessageType.AssertFailed);
                            OrdersSent.Remove(key);
                        }
                    }
                    //This must be an order we don't manage or that we have already rejected so the counter is considered to be not working
                }
            }
            catch (Exception ex)
            {
                DoLog(string.Format("<{0}>-Critical error processing a execution report:{1}", Configuration.Name, ex.Message), Constants.MessageType.AssertFailed);
            }
        }