Esempio n. 1
0
        /// <summary>
        /// Set Last Price of a Stock
        /// </summary>
        private void SetLastPrice()
        {
            Console.WriteLine("Set Last Price related to which Symbol ?");
            string symbol = Console.ReadLine();

            GenericStock workingStock = null;

            foreach (GenericStock stock in Stocks)
            {
                if (stock.Symbol == symbol.ToUpper())
                {
                    workingStock = stock;
                }
            }

            if (workingStock == null)
            {
                Console.WriteLine("Symbol not found!");
                return;
            }

            Console.WriteLine("Insert last Price:");
            string sprice = Console.ReadLine();

            float price;

            if (!float.TryParse(sprice, out price))
            {
                Console.WriteLine("Invalid numeric value");
                return;
            }

            workingStock.LastPrice = price;
        }
Esempio n. 2
0
        /// <summary>
        /// Method to show the trade list of a stock
        /// </summary>
        private void ShowTrades()
        {
            Console.WriteLine("Show trades related to which Symbol ?");
            string symbol = Console.ReadLine();

            GenericStock workingStock = null;

            foreach (GenericStock stock in Stocks)
            {
                if (stock.Symbol == symbol.ToUpper())
                {
                    workingStock = stock;
                }
            }

            if (workingStock == null)
            {
                Console.WriteLine("Symbol not found!");
                return;
            }

            if (workingStock.Trades.Count > 0)
            {
                Console.WriteLine("{0,20}\tB/S\tQty\tPrice", "Timestamp");
                foreach (Trade trade in workingStock.Trades)
                {
                    PrintTrade(trade);
                }
            }
            else
            {
                Console.WriteLine("No trades recorded!");
            }

            Console.WriteLine("Last 15 minutes Volume Weighted Price: {0:#0.00}",
                              workingStock.Trades.GetVolumeWeightedPrice(new TimeSpan(0, 15, 0)));
        }
Esempio n. 3
0
        /// <summary>
        /// Method to record a trade
        /// </summary>
        private void RecordATrade()
        {
            Console.WriteLine("Record a trade related to which Symbol ?");
            string symbol = Console.ReadLine();

            GenericStock workingStock = null;

            foreach (GenericStock stock in Stocks)
            {
                if (stock.Symbol == symbol.ToUpper())
                {
                    workingStock = stock;
                }
            }

            if (workingStock == null)
            {
                Console.WriteLine("Symbol not found!");
                return;
            }

            Console.WriteLine("Related to which date/time ?");
            string stimestamp = Console.ReadLine();

            DateTime timestamp = DateTime.Now;

            if (!DateTime.TryParse(stimestamp, out timestamp))
            {
                Console.WriteLine("Invalid date/time");
                return;
            }

            Console.WriteLine("B - Buy or S - Sell ?");
            string sbs = Console.ReadLine();

            TRADE_SIGN sign;

            if (sbs.ToUpper() == "B")
            {
                sign = TRADE_SIGN.Buy;
            }
            else if (sbs.ToUpper() == "S")
            {
                sign = TRADE_SIGN.Sell;
            }
            else
            {
                Console.WriteLine("Invalid Operation!");
                return;
            }

            Console.WriteLine("Quantity ?");
            string sqty = Console.ReadLine();

            int qty;

            if (!int.TryParse(sqty, out qty))
            {
                Console.WriteLine("Invalid Quantity!");
                return;
            }

            Console.WriteLine("Price (in pennies) ?");
            string sprice = Console.ReadLine();

            float price;

            if (!float.TryParse(sprice, out price))
            {
                Console.WriteLine("Invalid price!");
                return;
            }

            Trade trade = new Trade(timestamp, qty, sign, price);

            PrintTrade(trade);
            Console.WriteLine("Add to Stock {0} ? (Y to confirm or any other input to cancel)", workingStock.Symbol);
            string answer = Console.ReadLine();

            if (answer.ToUpper() == "Y")
            {
                workingStock.Trades.Add(trade);
            }
            else
            {
                Console.WriteLine("Operation cancelled!");
            }
        }