示例#1
0
        public async Task <NewsArticle> GetEarningsSummary(string symbol)
        {
            string headline;

            var profile = (await _barchartClient.GetProfiles(new [] { symbol },
                                                             new []
            {
                "qtrOneEarnings", "qtrOneEarningsDate", "qtrTwoEarnings", "qtrTwoEarningsDate",
                "qtrThreeEarnings", "qtrThreeEarningsDate", "qtrFourEarnings", "qtrFourEarningsDate"
            })).FirstOrDefault();
            var chart = await _barchartClient.GetChart(symbol);

            var earnings = await _barchartClient.GetCorporateActions(new[] { symbol }, null, null, EventType.earnings);

            var earning  = earnings.FirstOrDefault();
            var estimate = await _barchartClient.GetEarningsEstimates(new[] { symbol });

            var qtrEstimate = estimate.FirstOrDefault(x => x.Period.Contains("Qtr"));

            if (earning.EventDate == profile.QtrOneEarningsDate.Value)
            {
                headline = $"{profile.ExchangeName} reports first quarter earnings of {profile.QtrOneEarnings}";
            }
            else if (earning.EventDate == profile.QtrTwoEarningsDate.Value)
            {
                headline = $"{profile.ExchangeName} reports second quarter earnings of {profile.QtrTwoEarnings}";
            }
            else if (earning.EventDate == profile.QtrThreeEarningsDate.Value)
            {
                headline = $"{profile.ExchangeName} reports third quarter earnings of {profile.QtrThreeEarnings}";
            }
            else
            {
                headline = $"{profile.ExchangeName} reports fourth quarter earnings of {profile.QtrFourEarnings}";
            }

            var body = $"{profile.ExchangeName} (<a href=\"{_companyUrl + profile.Symbol}\">{profile.Exchange}:{profile.Symbol}</a>)" +
                       $" reported on {earning.EventDate.DayOfWeek}, {earning.EventDate : MMMM dd} earnings of {earning.Value}." +
                       $"Last quarter's earnings was {earnings.ElementAt(1).Value}. Next" +
                       $" quarter earnings are projected to be {qtrEstimate.AverageEstimate}.";

            return(new NewsArticle(headline, body, chart.ImageUrl));
        }
示例#2
0
        public async Task <ActionResult> GetProfile(string symbol)
        {
            ViewBag.Profile = await _barchartClient.GetProfiles(symbol);

            ViewBag.Quote = (await _barchartClient.GetQuote(new[] { symbol }, new[] { "R" },
                                                            new[] { "previousClose", "bid", "ask", "fiftyTwoWkLow", "fiftyTwoWkHigh", "avgVolume" }))
                            ?.ElementAt(0);
            ViewBag.FinancialHighlight = (await _barchartClient.GetFinancialHighlights(new[] { symbol },
                                                                                       new[] { "beta", "peRatio", "ttmEPS" }))
                                         ?.ElementAt(0);
            ViewBag.Estimate = (await _barchartClient.GetEarningsEstimates(new[] { symbol },
                                                                           new[] { "exDividendDate", "dividendRate" }))
                               ?.ElementAt(0);
            ViewBag.Chart = await _barchartClient.GetChart(symbol);

            ViewBag.NewsArticles = (await _barchartClient.GetNews(symbol))
                                   .Take(10)
                                   .Select(n => new NewsArticle(n.NewsID, n.Headline, n.Preview));

            var earnings = await _barchartClient.GetCorporateActions(new[] { symbol }, null, null, EventType.earnings, 5);

            var dividends = await _barchartClient.GetCorporateActions(new[] { symbol }, null, null, EventType.dividend, 5);

            if (dividends == null)
            {
                ViewBag.Earnings = earnings.Select(e => new EarningsData {
                    Earnings = e
                });
            }
            else if (earnings == null)
            {
                ViewBag.Earnings = dividends.Select(d => new EarningsData {
                    Dividends = d
                });
            }
            else
            {
                ViewBag.Earnings = earnings.Join(dividends, e => e.EventDate.Month, d => d.EventDate.Month,
                                                 (e, d) => new EarningsData {
                    Earnings = e, Dividends = d
                });
            }

            return(View("Profile"));
        }