Exemplo n.º 1
0
        static void WebImplementation()
        {
            OrderMatchList = new OrderMatchList(CurrentPrice);
            TradeRecord.SetTradeRecordStartId(TradeRecordStartId);
            TradeRecordList = new List <TradeRecord>();

            IPAddress   hostIp   = Dns.GetHostAddresses(WebHostMatchEngineIp)[0];
            TcpListener listener = new TcpListener(hostIp, WebHostMatchEnginePort);

            listener.Start();
            Console.WriteLine("Waiting for connection...");
            while (true)
            {
                TcpClient     client = listener.AcceptTcpClient();
                NetworkStream ns     = client.GetStream();

                byte[] byteNewOrder           = new byte[1024];
                int    byteNewOrderRealLength = ns.Read(byteNewOrder, 0, byteNewOrder.Length);
                Order  newOrder = Xml.Deserialize(typeof(Order), Encoding.UTF8.GetString(byteNewOrder, 0, byteNewOrderRealLength)) as Order;
                Console.WriteLine("Order is received and latest price is sent.");
                TradeRecordList.AddRange(PrintTradeRecord(OrderMatchList.AddOrderGetTradeRecord(newOrder)));

                CurrentPrice = OrderMatchList.CurrentPrice;
                byte[] bytePrice = Encoding.ASCII.GetBytes(CurrentPrice.ToString());
                ns.Write(bytePrice, 0, bytePrice.Length);
                client.Close();
            }
        }
Exemplo n.º 2
0
        static void ReceiveOrderFromMessageQueue(Object source, ElapsedEventArgs e)
        {
            Order newOrder = (OrderQueue.Receive().Body) as Order;

            TradeRecordList.AddRange(PrintTradeRecord(OrderMatchList.AddOrderGetTradeRecord(newOrder)));
            if (CurrentPrice != OrderMatchList.CurrentPrice)
            {
                CurrentPrice = OrderMatchList.CurrentPrice;
                PriceQueue.Send(OrderMatchList.CurrentPrice);
            }
        }
Exemplo n.º 3
0
        static void FileImplementation()
        {
            Order[] OrderQueue = new Order[FileOrderAmount];
            ReadOrderFromXml(ref OrderQueue);

            OrderMatchList = new OrderMatchList(CurrentPrice);
            TradeRecord.SetTradeRecordStartId(TradeRecordStartId);
            TradeRecordList = new List <TradeRecord>();

            for (int i = 0; i < FileOrderAmount; i++)
            {
                TradeRecordList.AddRange(OrderMatchList.AddOrderGetTradeRecord(OrderQueue[i]));
            }
            WriteTradeRecordToXml(ref TradeRecordList);
        }