Web Api Blog

 
 
 

Api to find stock's Key Stats based on its publicly traded stock symbol. IEX Trading api is a best an reliable, alternative to Yahoo Finance and Google Finance Api.

Stock's Key Stats data - IEX Trading Api

Consuming Stock's Key Stats Info - IEX Trading api using Postman:

Web Api Url: https://api.iextrading.com/1.0/stock/msft/stats

Api Response:

{
companyName: "Microsoft Corporation",
marketcap: 659906045280,
beta: 0.999318,
week52high: 87.4999,
week52low: 61.95,
week52change: 39.0302,
shortInterest: 49744915,
shortDate: "2017-12-15",
dividendRate: 1.68,
dividendYield: 1.9639934,
exDividendDate: "2018-02-14 00:00:00.0",
latestEPS: 2.83,
latestEPSDate: "2017-06-30",
sharesOutstanding: 7714590195,
float: 7254764846,
returnOnEquity: 27.64,
consensusEPS: 0.69,
numberOfEstimates: 15,
EPSSurpriseDollar: null,
EPSSurprisePercent: 5.7971,
symbol: "MSFT",
EBITDA: 37726000000,
revenue: 94035000000,
grossProfit: 59340000000,
cash: 520251000000,
debt: 346415000000,
ttmEPS: 3.0100000000000002,
revenuePerShare: 12,
revenuePerEmployee: 758347,
peRatioHigh: 38.4,
peRatioLow: 11.9,
returnOnAssets: 9.58,
returnOnCapital: null,
profitMargin: 24.55,
priceToSales: 7.032431,
priceToBook: 7.36,
day200MovingAvg: 73.36598,
day50MovingAvg: 83.24141,
institutionPercent: 57.7,
insiderPercent: 6,
shortRatio: 1.941354,
year5ChangePercent: 2.0970311368573498,
year2ChangePercent: 0.5609489051094892,
year1ChangePercent: 0.36689038031319926,
ytdChangePercent: 0,
month6ChangePercent: 0.2548041660554497,
month3ChangePercent: 0.14649510789438422,
month1ChangePercent: 0.015191075243294577,
day5ChangePercent: 0.0003508361595135205
}

C# Code for finding Stock's Key Stats info


Step 1:

Create a console application


Step 2:

Add following nuget packages

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" />
  <package id="Newtonsoft.Json" version="10.0.3" targetFramework="net45" />
</packages>

Step 3:

Create a C# POCO class for storing Json Response.

public class KeyStatsResponse
{
    public string companyName { get; set; }
    public long marketcap { get; set; }
    public double beta { get; set; }
    public double week52high { get; set; }
    public double week52low { get; set; }
    public double week52change { get; set; }
    public int shortInterest { get; set; }
    public string shortDate { get; set; }
    public double dividendRate { get; set; }
    public double dividendYield { get; set; }
    public string exDividendDate { get; set; }
    public double latestEPS { get; set; }
    public string latestEPSDate { get; set; }
    public long sharesOutstanding { get; set; }
    public long @float { get; set; }
    public double returnOnEquity { get; set; }
    public double consensusEPS { get; set; }
    public int numberOfEstimates { get; set; }
    public string EPSSurpriseDollar { get; set; }
    public double EPSSurprisePercent { get; set; }
    public string symbol { get; set; }
    public long EBITDA { get; set; }
    public long revenue { get; set; }
    public long grossProfit { get; set; }
    public long cash { get; set; }
    public long debt { get; set; }
    public double ttmEPS { get; set; }
    public int revenuePerShare { get; set; }
    public int revenuePerEmployee { get; set; }
    public double peRatioHigh { get; set; }
    public double peRatioLow { get; set; }
    public double returnOnAssets { get; set; }
    public string returnOnCapital { get; set; }
    public double profitMargin { get; set; }
    public double priceToSales { get; set; }
    public double priceToBook { get; set; }
    public double day200MovingAvg { get; set; }
    public double day50MovingAvg { get; set; }
    public double institutionPercent { get; set; }
    public int insiderPercent { get; set; }
    public double shortRatio { get; set; }
    public double year5ChangePercent { get; set; }
    public double year2ChangePercent { get; set; }
    public double year1ChangePercent { get; set; }
    public int ytdChangePercent { get; set; }
    public double month6ChangePercent { get; set; }
    public double month3ChangePercent { get; set; }
    public double month1ChangePercent { get; set; }
    public double day5ChangePercent { get; set; }
}

Step 4:

Write Web API Consumer for Get Request

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace KeystatsInfo
{
    class Program
    {
        static void Main(string[] args)
        {
            var symbol = "msft";
            var IEXTrading_API_PATH = "https://api.iextrading.com/1.0/stock/{0}/stats";

            IEXTrading_API_PATH = string.Format(IEXTrading_API_PATH, symbol);

            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                //For IP-API
                client.BaseAddress = new Uri(IEXTrading_API_PATH);
                HttpResponseMessage response = client.GetAsync(IEXTrading_API_PATH).GetAwaiter().GetResult();
                if (response.IsSuccessStatusCode)
                {
                    var keyStatsData = response.Content.ReadAsAsync<KeyStatsResponse>().GetAwaiter().GetResult();                    
                    if (keyStatsData != null)
                    {
                        Console.WriteLine("Company Name: " + keyStatsData.companyName);
                        Console.WriteLine("Market cap: " + keyStatsData.marketcap);
                        Console.WriteLine("Earning Per Share (EPS): " + keyStatsData.latestEPS);
                        Console.WriteLine("Return On Equity: " + keyStatsData.returnOnEquity);
                        Console.WriteLine("EBITDA: " + keyStatsData.EBITDA);
                        Console.WriteLine("Gross Profit: " + keyStatsData.grossProfit);
                        Console.WriteLine("200 day Moving Avg: " + keyStatsData.day200MovingAvg);
                        Console.WriteLine("50 day Moving Avg: " + keyStatsData.day50MovingAvg);
                        Console.WriteLine("5 years Change Percent: " + keyStatsData.year5ChangePercent);
                        Console.WriteLine("2 years Change Percent: " + keyStatsData.year2ChangePercent);
                        Console.WriteLine("1 years Change Percent: " + keyStatsData.year1ChangePercent);
                        Console.WriteLine("6 months Change Percent: " + keyStatsData.month6ChangePercent);
                        Console.WriteLine("3 months Change Percent: " + keyStatsData.month3ChangePercent);
                        Console.WriteLine("1 month Change Percent: " + keyStatsData.month1ChangePercent);
                        Console.WriteLine("5 days Change Percent: " + keyStatsData.day5ChangePercent);
                    }                   
                }
            }
        }
    }


    public class KeyStatsResponse
    {
        public string companyName { get; set; }
        public long marketcap { get; set; }
        public double beta { get; set; }
        public double week52high { get; set; }
        public double week52low { get; set; }
        public double week52change { get; set; }
        public int shortInterest { get; set; }
        public string shortDate { get; set; }
        public double dividendRate { get; set; }
        public double dividendYield { get; set; }
        public string exDividendDate { get; set; }
        public double latestEPS { get; set; }
        public string latestEPSDate { get; set; }
        public long sharesOutstanding { get; set; }
        public long @float { get; set; }
        public double returnOnEquity { get; set; }
        public double consensusEPS { get; set; }
        public int numberOfEstimates { get; set; }
        public string EPSSurpriseDollar { get; set; }
        public double EPSSurprisePercent { get; set; }
        public string symbol { get; set; }
        public long EBITDA { get; set; }
        public long revenue { get; set; }
        public long grossProfit { get; set; }
        public long cash { get; set; }
        public long debt { get; set; }
        public double ttmEPS { get; set; }
        public int revenuePerShare { get; set; }
        public int revenuePerEmployee { get; set; }
        public double peRatioHigh { get; set; }
        public double peRatioLow { get; set; }
        public double returnOnAssets { get; set; }
        public string returnOnCapital { get; set; }
        public double profitMargin { get; set; }
        public double priceToSales { get; set; }
        public double priceToBook { get; set; }
        public double day200MovingAvg { get; set; }
        public double day50MovingAvg { get; set; }
        public double institutionPercent { get; set; }
        public int insiderPercent { get; set; }
        public double shortRatio { get; set; }
        public double year5ChangePercent { get; set; }
        public double year2ChangePercent { get; set; }
        public double year1ChangePercent { get; set; }
        public int ytdChangePercent { get; set; }
        public double month6ChangePercent { get; set; }
        public double month3ChangePercent { get; set; }
        public double month1ChangePercent { get; set; }
        public double day5ChangePercent { get; set; }
    }
}

Note: IEX Trading is 100% Free and reliable api to get stock market data. The free API is built on a proven, high-performance system, and drives many of the applications we use within IEX. Usage of IEX Trading api - 100 requests per second.


 
 
Didn't find what you were looking for? Find more on Get Stock Key Stats based on it stock symbol - IEXTrading Api - C#