Example #1
0
        }// Process()

        private void ProcessDataReceived()
        {
            if (sb.Length > 0)
            {
                bool bQuit = (String.Compare(sb.ToString(), "quit", true) == 0);

                data = sb.ToString();

                sb.Length = 0; // Clear buffer

                Console.WriteLine("Executed Order Confimation received from Exchange:");

                RandomGauss.OrderExecuted(Program.LoadFromXMLString(data));

                string response;
                response = ("Confirmation Received at " + DateTime.Now.ToShortTimeString());


                // Echo the data back to the client.
                byte[] sendBytes = Encoding.ASCII.GetBytes(response.ToString());
                networkStream.Write(sendBytes, 0, sendBytes.Length);

                // Client stop processing
                if (bQuit)
                {
                    networkStream.Close();
                    ClientSocket.Close();
                    ContinueProcess = false;
                }
            }
        }
Example #2
0
        public static void ReceiveQuote(RandomGauss randLink)
        {
            NameValueCollection configuration = ConfigurationManager.AppSettings;
            IPAddress           GroupAddress  = IPAddress.Parse(configuration["GroupAddress"]);
            int localPort  = int.Parse(configuration["LocalPort"]);
            int remotePort = int.Parse(configuration["RemotePort"]);
            int ttl        = int.Parse(configuration["TTL"]);

            Socket sock = new Socket(AddressFamily.InterNetwork,
                                     SocketType.Dgram, ProtocolType.Udp);
            IPEndPoint iep = new IPEndPoint(IPAddress.Any, remotePort);

            sock.Bind(iep);
            EndPoint ep = (EndPoint)iep;

            //Console.WriteLine("Ready to receiveā€¦");
            byte[] data       = new byte[1024];
            int    recv       = sock.ReceiveFrom(data, ref ep);
            string stringData = Encoding.ASCII.GetString(data, 0, recv);

            //Console.WriteLine("received: {0} from: {1}", stringData, ep.ToString());
            data       = new byte[1024];
            recv       = sock.ReceiveFrom(data, ref ep);
            stringData = Encoding.ASCII.GetString(data, 0, recv);

            //Console.WriteLine("received: {0} from: {1}", stringData, ep.ToString());
            sock.Close();
            string[] quote = stringData.Split(',');
            Price.SetCurrentPrice(quote[0].ToString(), quote[1].ToString(), quote[2].ToString());
            //randLink.SetCurrentPrice(quote[0].ToString(), quote[1].ToString(), quote[2].ToString());
        }
Example #3
0
        static void Main(string[] args)
        {
            //Console.WriteLine("Press any key to continue...");
            //Console.ReadKey(false);


            //Console.WriteLine(data_in.ReadToEnd());

            ////when we're done, close up shop.
            //data_in.Close();
            //tcp.Close();

            //this is just to pause the console so you can see what's going on.
            Console.WriteLine("Press any key to continue...");
            //Console.ReadKey(false);


            RandomGauss rand = new RandomGauss();



            Task[] tasks = new Task[threadCount];

            for (int i = 0; i < threadCount; i++)
            {
                //RandomGauss rand = new RandomGauss();
                tasks[i] = Task.Factory.StartNew(() => rand.starter());
            }
            Task.WaitAll(tasks);

            XMLBlaster  server = new XMLBlaster();
            RandomGauss rand2  = new RandomGauss();

            //rand2.start2();
            server.myXML = rand.getOrders();
            server.Begin();

            //TcpClient tcp = new TcpClient(AddressFamily.InterNetwork);
            //tcp.Connect(IPAddress.Loopback, 12345);


            //StreamReader data_in = new StreamReader(tcp.GetStream());
            //string myxml = data_in.ReadToEnd();

            //EquityOrder[] newOrder = LoadFromXMLString(myxml);

            //data_in.Close();

            //rand.getOrders();


            //Console.WriteLine(rand.getOrders());

            Console.WriteLine("Press any key to continue");
            Console.ReadLine();
        }
Example #4
0
        public void startQuoteListener(Object a)
        {
            RandomGauss randLink = a as RandomGauss;

            while (true)
            {
                orderSignaler.WaitOne(1000);
                ReceiveQuote(randLink);
            }
        }
Example #5
0
        static void Main(string[] args)
        {
            ManualResetEvent orderSignaler = new ManualResetEvent(false);

            RandomGauss[] traders = new RandomGauss[threadCount];

            for (int i = 0; i < threadCount; i++)
            {
                traders[i] = new RandomGauss(i);
            }

            //sets up listener for price quotes
            QuoteReceiver newQuote = new QuoteReceiver();

            ThreadPool.QueueUserWorkItem(new WaitCallback(newQuote.startQuoteListener));

            //SynchronousSocketListener newExecutedOrderListener = new SynchronousSocketListener();
            Task.Factory.StartNew(() => SynchronousSocketListener.StartListening());



            Task[] tasks = new Task[threadCount];


            for (int j = 0; j < 10000; j++)
            {
                for (int trader = 0; trader < threadCount; trader++)
                {
                    tasks[trader] = Task.Factory.StartNew(() => traders[trader].start(new FuturesOrder()));

                    orderSignaler.WaitOne(1000);//we can update this to be a random pause
                }
                //Task.WaitAll(tasks); if we have the pause I don't think we need to wait for all threads to finish
            }
            //Task.WaitAll(tasks);
            Console.WriteLine("Press any key to continue");
            Console.ReadLine();
        }