/// <summary> /// Gets the market data. /// </summary> /// <param name="companyName">Name of the company.</param> /// <returns></returns> public async Task <string> GetMarketData(string companyName) { _logger.LogTrace("Starting to obtain quotes"); var tickersToUse = await _resolveCompanyName.ResolveCompanyNameOrTicker(companyName); if (tickersToUse.IsNullOrWhiteSpace()) { return($"We could not resolve ticker/company Name {companyName}; possible reason Google registered name is Alphabet Inc.\n\n" + $"Hint: try with symbol or ticker"); } var quotes = await GetStockQuotes(tickersToUse); string returnValueMsg; if (quotes != null && quotes.Data != null && quotes.Data.Any()) { returnValueMsg = BuildOutputMsg(quotes); return(returnValueMsg); } var wtQuotes = await GetStockQuotesFromWT(tickersToUse); returnValueMsg = BuildOutputMsg(wtQuotes); if (returnValueMsg.IsNullOrWhiteSpace()) { return($"We tried; but couldn't get the quotes for {companyName}"); } return(returnValueMsg); }
public async Task <string> GetCompanyFundamentals(string companyName) { _logger.LogTrace("Starting fundamental details"); var tickersToUse = await _resolveCompanyName.ResolveCompanyNameOrTicker(companyName); if (tickersToUse.IsNullOrWhiteSpace()) { return($"We could not resolve ticker/company Name {companyName}; possible reason Google registered name is Alphabet Inc.\n\n" + $"Hint: try with symbol or ticker"); } var fulfillmentText = new StringBuilder(); try { int counter = 0; foreach (var ticker in tickersToUse.Split(',')) { var ratingsMd = _connectionHandlerCF.Get().Where(x => x.Ticker.ToLower().Equals(ticker.ToLower())) .OrderByDescending(x => x.FYear).FirstOrDefault(); PiotroskiScore computedRating = null; if (ratingsMd != null && DateTime.Now.Year - ratingsMd.FYear <= 2) { computedRating = _mapper.Map <PiotroskiScore>(ratingsMd); } fulfillmentText.Append(await BuildCompanyProfile(ticker, computedRating)); if (++counter >= 2) { break; } } if (counter >= 2) { fulfillmentText.Append($"Limiting result set as the search term {companyName} resolved to too many results.\n"); } } catch (Exception ex) { _logger.LogCritical($"Error while processing Get Company Fundamentals; \n{ex.Message}"); return(""); } if (fulfillmentText.ToString().Contains("Piotroski")) { fulfillmentText.Append("\nNote: Piotroski F-Score is based on company fundamentals; " + "a rating greater than 6 indicates strong fundamentals."); } return(fulfillmentText.ToString()); }