示例#1
0
        //Mike B
        public override void ProcessOrder(Order newOrder)
        {
            if (EquityMatchingEngine.OMEHost.open == false)//during staging period
            {
                if (newOrder.OrderType == "MARKET")
                {
                    orderBook.ordersInProcess.Remove(newOrder.OrderID.ToString());//need to put this somewhere else
                    tmpMktorderDataStore.Add(newOrder);
                    tmpMktorderDataStore.Sort(orderBook.OrderPriority);
                }
                else if (newOrder.OrderType == "LIMIT")
                {
                    orderBook.ordersInProcess.Remove(newOrder.OrderID.ToString());
                    orderDataStore.Add(newOrder);
                    orderDataStore.Sort(orderBook.OrderPriority);
                }
                else if (newOrder.OrderType == "STOP")
                {
                    orderBook.ordersInProcess.Remove(newOrder.OrderID.ToString());
                    stopOrderDataStore.Add(newOrder);
                    orderDataStore.Sort(orderBook.OrderPriority);
                }
                return;
            }
            if (exchangeRunning == false && EquityMatchingEngine.OMEHost.open == true)//matched trades already in book
            {
                exchangeRunning = true;
                openPriceFound.Reset();
                OpenExchange();
            }
            openPriceFound.WaitOne();//wait for open

            Container buyBook  = parentContainer.ChildContainers["B"];
            Container sellBook = parentContainer.ChildContainers["S"];

            OrderEventArgs orderArgs = new OrderEventArgs(newOrder, buyBook, sellBook);


            orderBook.ordersInProcess.Remove(newOrder.OrderID.ToString());
            if (newOrder.Active == true)
            {
                orderBook.OnOrderBeforeInsert(orderArgs);

                if (newOrder.Quantity > 0 && newOrder.OrderType == "MARKET")    //no available limit orders to match orders with so send back to client
                {
                    newOrder.Message = "Order could not be completed, not enough open orders";
                    ExecutedOrdersToSend.TcpClientTest.Connect(EquityMatchingEngine.OMEHost.ToXML(newOrder));
                }
                else if (newOrder.Quantity > 0)
                {
                    orderDataStore.Add(newOrder);

                    orderDataStore.Sort(orderBook.OrderPriority);
                    orderBook.OnOrderInsert(orderArgs);
                }
            }
            newQuote.Set();
            if (stopOrderDataStore.Count > 0)
            {
                useResource();
            }
        }