コード例 #1
0
        public static CompanyResult GetStock(string input)
        {
            string urlMarkit = "http://dev.markitondemand.com/Api/v2/Quote/json?symbol=" + input;

            try
            {
                using (WebClient webClient = new WebClient())
                {
                    string json = webClient.DownloadString(urlMarkit);

                    var o = JObject.Parse(json);

                    CompanyResult cr = new CompanyResult();

                    cr.status = o["Status"].ToString();

                    if (cr.status == null)
                    {
                        Console.WriteLine("There is no data for " + input + ". Please make sure you have written the correct symbol for the company you are looking for.");
                        return(null);
                    }

                    else
                    {
                        cr.name = o["Name"].ToString();

                        cr.symbol = o["Symbol"].ToString();

                        cr.lastPrice = o["LastPrice"].ToString();

                        cr.low = o["Low"].ToString();

                        cr.high = o["High"].ToString();

                        string lastPrice = cr.lastPrice;

                        decimal priceParse = Convert.ToDecimal(lastPrice);

                        return(cr);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("There was an error, please try again.");
                return(null);
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("Welcome to Make it Rain 1.0");

                Console.WriteLine("Enter the symbol of the company");

                string symbolInput = Console.ReadLine();

                if (symbolInput.Length == 0)
                {
                    break;
                }

                CompanyResult companyResult = CompanyService.GetStock(symbolInput);

                CompanyResult currentStock = null;

                CompanyResult previousStock = null;

                while (true)
                {
                    previousStock = currentStock;

                    currentStock = CompanyService.GetStock(symbolInput);
                    System.Threading.Thread.Sleep(2000);


                    if (previousStock != null)
                    {
                        if (previousStock.priceParse > currentStock.priceParse)
                        {
                            Console.WriteLine("{0}, the company {1} has a price of {2} which is lower than before BUY!", companyResult.symbol, companyResult.name, companyResult.lastPrice);
                        }
                        else if (previousStock.lastPrice == currentStock.lastPrice)
                        {
                            Console.WriteLine("{0}, the company {1} has a price of {2} which is the same", companyResult.symbol, companyResult.name, companyResult.lastPrice);
                        }
                        else
                        {
                            Console.WriteLine("{0}, the company {1} has a price of {2} which is lower than before BUY!", companyResult.symbol, companyResult.name, companyResult.lastPrice);
                        }
                    }
                }
            }
        }