Beispiel #1
0
        /// <summary>
        /// Gets quotes by executing queries against Yahoo Finance using YQL
        /// </summary>
        /// <param name="stocks"></param>
        /// <returns></returns>
        public IEnumerable <StockQuote> GetQuotes(IEnumerable <Stock> stocks)
        {
            // if no stocks provided, return empty list
            if (stocks == null)
            {
                return(new List <StockQuote>());
            }

            // enumerate and check count; if no stocks provided, return empty list
            var stockList = stocks.ToList();

            if (stockList.Count == 0)
            {
                return(new List <StockQuote>());
            }

            // get url for query
            string queryUrl = _urlProvider.GetQuotesUrl(stockList.Select(s => s.Symbol));

            if (string.IsNullOrWhiteSpace(queryUrl))
            {
                throw new QueryUrlNotProvidedException();
            }

            // get results of query
            string results = _webRequestExecutor.ExecuteRequest(queryUrl);

            if (string.IsNullOrWhiteSpace(results))
            {
                throw new QueryResultsAreEmptyException();
            }

            // interpret response and return
            return(_quotesResultTranslator.TranslateResultsToQuotes(results));
        }