Exemplo n.º 1
0
        public async Task <string> GetFinancialSummary(string symbol)
        {
            var profile = await _barchartClient.GetProfiles(symbol);

            var quote = (await _barchartClient.GetQuote(new[] { symbol }, new[] { "D" },
                                                        new[] { "previousClose", "avgVolume", "averageWeeklyVolume" }))
                        ?.ElementAt(0);
            var technical = (await _barchartClient.GetTechnicals(new[] { symbol },
                                                                 new[] { "priceChangeYTD" }))?.ElementAt(0);
            var earning = await _barchartClient.GetCorporateActions(symbol, EventType.earnings);

            var dividend = await _barchartClient.GetCorporateActions(symbol, EventType.dividend);

            var estimate = await _barchartClient.GetEarningsEstimates(symbol);

            var oneDayVolumeChange  = (float)quote.Volume / quote.AvgVolume.Value - 1;
            var fiveDayVolumeChange = (float)quote.AverageWeeklyVolume.Value / quote.AvgVolume.Value - 1;
            var earningsChange      = (float)earning.Value / estimate.AverageEstimate - 1;

            return($"<h4>About {profile.ExchangeName}</h4>" +
                   $"<ul><li>{symbol} is at ${quote.LastPrice}, a {quote.PercentChange}% change from last trading day close of ${quote.PreviousClose}.</li>" +
                   $"<li>{symbol} had a volume of {quote.Volume}, {Math.Abs(oneDayVolumeChange): 0.##}% {(oneDayVolumeChange > 0 ? "above" : "below")} the year-to day volume of {quote.AvgVolume}." +
                   $" The average volume over the last five days ({quote.AverageWeeklyVolume}) is {(fiveDayVolumeChange > 0 ? "up" : "down")} {Math.Abs(fiveDayVolumeChange): 0.##}% compared to the average.</li>" +
                   $"<li>{symbol} has {(technical.PriceChangeYtd > 0 ? "increased" : "decreased")} {Math.Abs(technical.PriceChangeYtd.Value)}% since the start of the year.</li>" +
                   $"<li>{symbol} earnings of {earning.Value} is {Math.Abs(earningsChange): 0.##}% {(earningsChange > 0 ? "higher" : "lower")} than {estimate.AverageEstimate} as estimated.</li>" +
                   $"{(dividend != null ? $"<li>{symbol} last dividend was {dividend.Value}.</li></ul>" : "")}");
        }
Exemplo n.º 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"));
        }
Exemplo n.º 3
0
        public void GetCorporateActions()
        {
            var corporateAction = _barchartClient.GetCorporateActions(_symbol, EventType.dividend).Result;

            Assert.AreEqual(corporateAction.Symbol, _symbol);
        }