Web Api Blog

 
 
 

Api to find stock's Financial info based on its publicly traded stock symbol. Pulls income statement, balance sheet, and cash flow data from the four most recent reported quarters. IEX Trading api is a best an reliable, alternative to Yahoo Finance and Google Finance Api.

Stock's Financial Info - IEX Trading Api

Api for Stock's Financial Info - IEX Trading api using Postman:

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

Api Response:

{
symbol: "MSFT",
financials: [
{
reportDate: "2017-09-30",
grossProfit: 16260000000,
costOfRevenue: 8278000000,
operatingRevenue: 24538000000,
totalRevenue: 24538000000,
operatingIncome: 7708000000,
netIncome: 6576000000,
researchAndDevelopment: 3574000000,
operatingExpense: 8552000000,
currentAssets: 161031000000,
totalAssets: 249097000000,
totalLiabilities: 159450000000,
currentCash: 6884000000,
currentDebt: 9220000000,
totalCash: 138471000000,
totalDebt: 91243000000,
shareholderEquity: 89647000000,
cashChange: -779000000,
cashFlow: 12440000000,
operatingGainsLosses: -523000000
},
{
reportDate: "2017-06-30",
grossProfit: 14861000000,
costOfRevenue: 8456000000,
operatingRevenue: 23317000000,
totalRevenue: 23317000000,
operatingIncome: 5330000000,
netIncome: 6513000000,
researchAndDevelopment: 3514000000,
operatingExpense: 9531000000,
currentAssets: 159851000000,
totalAssets: 241086000000,
totalLiabilities: 168692000000,
currentCash: 7663000000,
currentDebt: 10121000000,
totalCash: 132981000000,
totalDebt: 86194000000,
shareholderEquity: 72394000000,
cashChange: 950000000,
cashFlow: 11005000000,
operatingGainsLosses: -520000000
},
{
reportDate: "2017-03-31",
grossProfit: 14030000000,
costOfRevenue: 8060000000,
operatingRevenue: 22090000000,
totalRevenue: 22090000000,
operatingIncome: 5594000000,
netIncome: 4801000000,
researchAndDevelopment: 3355000000,
operatingExpense: 8436000000,
currentAssets: 146313000000,
totalAssets: 225017000000,
totalLiabilities: 155288000000,
currentCash: 6713000000,
currentDebt: 7786000000,
totalCash: 126018000000,
totalDebt: 84008000000,
shareholderEquity: 69729000000,
cashChange: -1755000000,
cashFlow: 10660000000,
operatingGainsLosses: -590000000
},
{
reportDate: "2016-12-31",
grossProfit: 14189000000,
costOfRevenue: 9901000000,
operatingRevenue: 24090000000,
totalRevenue: 24090000000,
operatingIncome: 6177000000,
netIncome: 5200000000,
researchAndDevelopment: 3062000000,
operatingExpense: 8012000000,
currentAssets: 144949000000,
totalAssets: 224610000000,
totalLiabilities: 155801000000,
currentCash: 8468000000,
currentDebt: 25664000000,
totalCash: 122781000000,
totalDebt: 84970000000,
shareholderEquity: 68809000000,
cashChange: -5460000000,
cashFlow: 6293000000,
operatingGainsLosses: -652000000
}
]
}

C# Code for Stock's Financial 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 Financial
    {
        public string reportDate { get; set; }
        public string grossProfit { get; set; }
        public string costOfRevenue { get; set; }
        public string operatingRevenue { get; set; }
        public string totalRevenue { get; set; }
        public string operatingIncome { get; set; }
        public string netIncome { get; set; }
        public string researchAndDevelopment { get; set; }
        public string operatingExpense { get; set; }
        public string currentAssets { get; set; }
        public string totalAssets { get; set; }
        public string totalLiabilities { get; set; }
        public string currentCash { get; set; }
        public string currentDebt { get; set; }
        public string totalCash { get; set; }
        public string totalDebt { get; set; }
        public string shareholderEquity { get; set; }
        public string cashChange { get; set; }
        public string cashFlow { get; set; }
        public string operatingGainsLosses { get; set; }
    }

    public class FinancialInfo
    {
        public string symbol { get; set; }
        public List<Financial> financials { 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 FinancialInfo
{
    class Program
    {
        static void Main(string[] args)
        {
            var symbol = "msft";
            var IEXTrading_API_PATH = "https://api.iextrading.com/1.0/stock/{0}/financials";

            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 financialInfoList = response.Content.ReadAsAsync<FinancialInfo>().GetAwaiter().GetResult();
                    foreach (var financialInfo in financialInfoList.financials)
                    {
                        if (financialInfo != null)
                        {
                            Console.WriteLine("Report date: " + financialInfo.reportDate);
                            Console.WriteLine("Gross Profit: " + financialInfo.grossProfit);
                            Console.WriteLine("Cost Of Revenue: " + financialInfo.costOfRevenue);
                            Console.WriteLine("Total Revenue: " + financialInfo.totalRevenue);
                            Console.WriteLine("Net Income: " + financialInfo.netIncome);
                            Console.WriteLine("Total Assets: " + financialInfo.totalAssets);
                            Console.WriteLine("Total Liabilities: " + financialInfo.totalLiabilities);
                            Console.WriteLine("Current Cash: " + financialInfo.currentCash);
                            Console.WriteLine("Current Debt: " + financialInfo.currentDebt);
                            Console.WriteLine("Cash Flow: " + financialInfo.cashFlow);
                            Console.WriteLine("Operating Income: " + financialInfo.operatingIncome);
                            Console.WriteLine("Operating Expense: " + financialInfo.operatingExpense);
                        }
                    }                                    
                }
            }
        }
    }

    public class Financial
    {
        public string reportDate { get; set; }
        public string grossProfit { get; set; }
        public string costOfRevenue { get; set; }
        public string operatingRevenue { get; set; }
        public string totalRevenue { get; set; }
        public string operatingIncome { get; set; }
        public string netIncome { get; set; }
        public string researchAndDevelopment { get; set; }
        public string operatingExpense { get; set; }
        public string currentAssets { get; set; }
        public string totalAssets { get; set; }
        public string totalLiabilities { get; set; }
        public string currentCash { get; set; }
        public string currentDebt { get; set; }
        public string totalCash { get; set; }
        public string totalDebt { get; set; }
        public string shareholderEquity { get; set; }
        public string cashChange { get; set; }
        public string cashFlow { get; set; }
        public string operatingGainsLosses { get; set; }
    }

    public class FinancialInfo
    {
        public string symbol { get; set; }
        public List<Financial> financials { 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 Api for Stock Financial Info based on it stock symbol - IEXTrading Api - C#