Web Api Blog

 
 
 

Api to find stock's Dividends info based on its publicly traded stock symbol. Pulls 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 Dividends Info - IEX Trading Api

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

Web Api Url: https://api.iextrading.com/1.0/stock/msft/dividends/1y

Api Response:

[
{
exDate: "2017-11-15",
paymentDate: "2017-12-14",
recordDate: "2017-11-16",
declaredDate: "2017-09-19",
amount: 0.42,
flag: "",
type: "Dividend income",
qualified: "Q",
indicated: ""
},
{
exDate: "2017-08-15",
paymentDate: "2017-09-14",
recordDate: "2017-08-17",
declaredDate: "2017-06-13",
amount: 0.39,
flag: "",
type: "Dividend income",
qualified: "Q",
indicated: ""
},
{
exDate: "2017-05-16",
paymentDate: "2017-06-08",
recordDate: "2017-05-18",
declaredDate: "2017-03-14",
amount: 0.39,
flag: "",
type: "Dividend income",
qualified: "Q",
indicated: ""
},
{
exDate: "2017-02-14",
paymentDate: "2017-03-09",
recordDate: "2017-02-16",
declaredDate: "2016-11-30",
amount: 0.39,
flag: "",
type: "Dividend income",
qualified: "Q",
indicated: ""
}
]

C# Code for Stock's Dividends 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 Dividend
    {
        public string exDate { get; set; }
        public string paymentDate { get; set; }
        public string recordDate { get; set; }
        public string declaredDate { get; set; }
        public double amount { get; set; }
        public string flag { get; set; }
        public string type { get; set; }
        public string qualified { get; set; }
        public string indicated { 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 DividendInfo
{
    class Program
    {
        static void Main(string[] args)
        {
            var symbol = "msft";
            var IEXTrading_API_PATH = "https://api.iextrading.com/1.0/stock/{0}/dividends/1y";

            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 dividendInfoList = response.Content.ReadAsAsync<List<Dividend>>().GetAwaiter().GetResult();
                    foreach (var dividendInfo in dividendInfoList)
                    {
                        if (dividendInfo != null)
                        {
                            Console.WriteLine("Ex dividend Date: " + dividendInfo.exDate);
                            Console.WriteLine("Dividend Payment Date: " + dividendInfo.paymentDate);
                            Console.WriteLine("Dividend Amount: " + dividendInfo.amount);                            
                        }
                    }                                    
                }
            }
        }
    }

    public class Dividend
    {
        public string exDate { get; set; }
        public string paymentDate { get; set; }
        public string recordDate { get; set; }
        public string declaredDate { get; set; }
        public double amount { get; set; }
        public string flag { get; set; }
        public string type { get; set; }
        public string qualified { get; set; }
        public string indicated { 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 Dividends Info based on it stock symbol - IEXTrading Api - C#