Exemplo n.º 1
0
        public static void ProcessOrder(ExchangeAMd message)
        {
            if(message.Sequence <= LastHighestSequenceNumber)
                return;
            if(message.Sequence > LastHighestSequenceNumber + 1)
                //Inconsistent state (Message lost)
            LastHighestSequenceNumber = message.Sequence;

            LimitBook book;
            lock (Books)
            {
                book = Books.Find(b => b.Contract.Equals(message.Contract));
                if (book == null)
                {
                    var newBook = new LimitBook(message.Contract);
                    Books.Add(newBook);
                    book = newBook;
                }
            }
            if (message.Type == MessageType.NewLevel)
            {
                book.ProcessNewOrder(message);
            }
            if (message.Type == MessageType.UpdateLevel)
            {
                book.ProcessModifyOrder(message);
            }
            if (message.Type == MessageType.DeleteLevel)
            {
                book.ProcessDeleteOrder(message);
            }
        }
        public void ProcessNewOrder(ExchangeAMd message)
        {
            if (message.Side == LimitOrderSide.Sell)
            {
                ProcessSellAddOrder(message.Level, message.Price, message.Quantity);
            }

            if (message.Side == LimitOrderSide.Buy)
            {
                ProcessBuyAddOrder(message.Level, message.Price, message.Quantity);
            }
        }
        public void ProcessDeleteOrder(ExchangeAMd message)
        {
            if(message.Side == LimitOrderSide.Sell)
            {
                ProcessSellDeleteOrder(message.Level);
            }

            if(message.Side == LimitOrderSide.Buy)
            {
                ProcessBuyDeleteOrder(message.Level);
            }
        }
Exemplo n.º 4
0
        public void GenerateData()
        {
            var contract = new List<string>() {"APPLE","IBM","GOOGLE","MICROSOFT","AMAZON","FACEBOOK"};

            bool sideFlag = false;
            var random = new Random();
            var sequence = 1;
            //UDPClient clientOne = new UDPClient(EP1);
            //UDPClient clientTwo = new UDPClient(EP2);

            for (int i = 0; i < 5; i++)
            {
                for (int j = 1; j < 6; j++)
                {
                    var side = sideFlag ? LimitOrderSide.Sell : LimitOrderSide.Buy;
                    sideFlag = sideFlag != true;
                    var message = new ExchangeAMd(sequence++, contract[i], j, random.Next(500), random.Next(500), side,
                                                  MessageType.NewLevel);
                    var randomNum = random.Next(100);
                    string data = JsonHelper.JsonSerializer(message);

                    if (randomNum <= 100*ProbabilityParameter)
                    {
                        Client.Client.ProcessOrder(message);
                        Client.Client.ProcessOrder(message);
                        //clientOne.Send(data);
                        //clientTwo.Send(data);
                    }
                    else
                    {
                        Client.Client.ProcessOrder(message);
                        Client.Client.ProcessOrder(message);
                        //clientTwo.Send(data);
                        //clientOne.Send(data);
                    }
                }
            }
        }