示例#1
0
        public yQuote StockQuote(string ticker, string url)
        {


            yQuote qte = new yQuote();
            string requesturl = url;
            requesturl = requesturl.Replace("||TICKER||", ticker);

            // MAKE WEB REQUEST TO THE URL
            WebRequest request = WebRequest.Create(requesturl);
            WebResponse response = request.GetResponse();

            Stream receive = response.GetResponseStream();
            Encoding encoding = Encoding.GetEncoding("utf-8");
            StreamReader read = new StreamReader(receive, encoding);

            string content = read.ReadToEnd();

            // DESERIALIZE THE JSON RESPONSE TO AN OBJECT
            JObject yahooresult = JObject.Parse(content);
            JToken result = yahooresult["query"]["results"]["quote"];
            qte = JsonConvert.DeserializeObject<yQuote>(result.ToString());


            return qte;
        }
示例#2
0
        public yQuote StockQuote(string ticker, string url)
        {
            yQuote qte        = new yQuote();
            string requesturl = url;

            requesturl = requesturl.Replace("||TICKER||", ticker);

            // MAKE WEB REQUEST TO THE URL
            WebRequest  request  = WebRequest.Create(requesturl);
            WebResponse response = request.GetResponse();

            Stream       receive  = response.GetResponseStream();
            Encoding     encoding = Encoding.GetEncoding("utf-8");
            StreamReader read     = new StreamReader(receive, encoding);

            string content = read.ReadToEnd();

            // DESERIALIZE THE JSON RESPONSE TO AN OBJECT
            JObject yahooresult = JObject.Parse(content);
            JToken  result      = yahooresult["query"]["results"]["quote"];

            qte = JsonConvert.DeserializeObject <yQuote>(result.ToString());


            return(qte);
        }
示例#3
0
        public yQuote StockQuote(string ticker, string url)
        {
            yQuote qte    = new yQuote();
            JToken result = yahoo_query(url, ticker);

            qte = JsonConvert.DeserializeObject <yQuote>(result.ToString());
            return(qte);
        }
        /// <summary>
        /// This original method grabs the YQL url from the config file, but it was causing problems int testing
        /// so i created the second method where the url is manually passed in.
        /// </summary>
        /// <param name="ticker"></param>
        /// <returns></returns>
        public yQuote StockQuote(string ticker)
        {
            yQuote qte = new yQuote();
            string requesturl = ConfigurationManager.AppSettings["URL"];
            requesturl = requesturl.Replace("||TICKER||", ticker);

            // MAKE WEB REQUEST TO THE URL
            string content = MakeWebRequestToTheURL(requesturl);

            // DESERIALIZE THE JSON RESPONSE TO AN OBJECT
            JObject yahooresult = JObject.Parse(content);
            JToken result = yahooresult["query"]["results"]["quote"];
            qte = JsonConvert.DeserializeObject<yQuote>(result.ToString());

            return qte;
        }
示例#5
0
        public List <yQuote> StockQuote(List <string> tickers, string url)
        {
            yQuote        qte            = new yQuote();
            List <yQuote> quotes         = new List <yQuote>();
            string        ticker_request = "";

            foreach (string symbol in tickers)
            {
                ticker_request += symbol;
                ticker_request += ",";
            }
            ticker_request = ticker_request.TrimEnd(';');
            JToken result = yahoo_query(url, ticker_request);

            quotes = JsonConvert.DeserializeObject <List <yQuote> >(result.ToString());
            return(quotes);
        }