Esempio n. 1
0
        public void Start(ITrader trader)
        {
            Console.WriteLine("Enter a stock symbol (for example aapl):");
            string symbol = Console.ReadLine();

            Console.WriteLine("Enter the maximum price you are willing to pay: ");
            double price;

            while (!double.TryParse(Console.ReadLine(), out price))
            {
                Console.WriteLine("Please enter a number.");
            }
            Console.WriteLine(trader.GetService().GetAPIPath());
            try {
                bool purchased = trader.Buy(symbol, price);
                if (purchased)
                {
                    Logger.Instance.Log("Purchased stock!");
                }
                else
                {
                    Logger.Instance.Log("Couldn't buy the stock at that price.");
                }
            } catch (Exception e) {
                Logger.Instance.Log("There was an error while attempting to buy the stock: " + e.Message);
            }
            Console.ReadLine();
        }