public string GetPriceFromYahoo(string tickerSymbol) { string price; string url = string.Format("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20csv%20where%20url='http%3A//download.finance.yahoo.com/d/quotes.csv?s={0}%26f=sl1'%20and%20columns='symbol%2Cprice'", tickerSymbol); try { Uri uri = new Uri(url); HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri); HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); XDocument doc = XDocument.Load(resp.GetResponseStream()); resp.Close(); var ticker = from query in doc.Descendants("query") from results in query.Descendants("results") from row in query.Descendants("row") let xElement = row.Element("price") where xElement != null select new { price = xElement.Value }; price = ticker.First().price; } catch (Exception ex) { LCDMessageBoxController lm = new LCDMessageBoxController(); lm.LogEvent("Exception retrieving symbol: " + tickerSymbol + " \n" + ex.Message, EventLogEntryType.Error); price = "Exception retrieving symbol: " + tickerSymbol; } return(price); }
/// <summary> /// The main entry point for the application. /// </summary> static void Main(string[] args) { if (Environment.UserInteractive) { LCDMessageBoxController controller = new LCDMessageBoxController(); controller.Start(); while (true) { Thread.Sleep(new TimeSpan(1, 0, 0)); } } else { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new LCDMessageBoxController() }; ServiceBase.Run(ServicesToRun); } }