Api to find stock's Historical data 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 Historical data - IEX Trading Api

Consuming Stock's Historical data api - IEX Trading api using Postman:

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

Api Response:

[
{
date: "2017-01-03",
open: 62.79,
high: 62.84,
low: 62.125,
close: 62.58,
volume: 20694101,
unadjustedVolume: 20694101,
change: 0.44,
changePercent: 0.708,
vwap: 62.4495,
label: "Jan 3, 17",
changeOverTime: 0
},
{
date: "2017-01-04",
open: 62.48,
high: 62.75,
low: 62.12,
close: 62.3,
volume: 21339969,
unadjustedVolume: 21339969,
change: -0.28,
changePercent: -0.447,
vwap: 62.3093,
label: "Jan 4, 17",
changeOverTime: -0.004474272930648788
},
{
date: "2017-01-05",
open: 62.19,
high: 62.66,
low: 62.03,
close: 62.3,
volume: 24875968,
unadjustedVolume: 24875968,
change: 0,
changePercent: 0,
vwap: 62.3595,
label: "Jan 5, 17",
changeOverTime: -0.004474272930648788
},
{
date: "2017-01-06",
open: 62.3,
high: 63.15,
low: 62.04,
close: 62.84,
volume: 19922919,
unadjustedVolume: 19922919,
change: 0.54,
changePercent: 0.867,
vwap: 62.7859,
label: "Jan 6, 17",
changeOverTime: 0.004154682007031082
},
{
date: "2017-01-09",
open: 62.76,
high: 63.08,
low: 62.54,
close: 62.64,
volume: 20382730,
unadjustedVolume: 20382730,
change: -0.2,
changePercent: -0.318,
vwap: 62.7501,
label: "Jan 9, 17",
changeOverTime: 0.0009587727708533441
},
...
]

C# Code for Stock's Historical data


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 HistoricalDataResponse
    {
        public string date { get; set; }
        public double open { get; set; }
        public double high { get; set; }
        public double low { get; set; }
        public double close { get; set; }
        public int volume { get; set; }
        public int unadjustedVolume { get; set; }
        public double change { get; set; }
        public double changePercent { get; set; }
        public double vwap { get; set; }
        public string label { get; set; }
        public double changeOverTime { 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 HistoricalDataInfo
{
    class Program
    {
        static void Main(string[] args)
        {
            var symbol = "msft";
            var IEXTrading_API_PATH = "https://api.iextrading.com/1.0/stock/{0}/chart/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 historicalDataList = response.Content.ReadAsAsync<List<HistoricalDataResponse>>().GetAwaiter().GetResult();
                    foreach (var historicalData in historicalDataList)
                    {
                        if (historicalData != null)
                        {
                            Console.WriteLine("Open: " + historicalData.open);
                            Console.WriteLine("Close: " + historicalData.close);
                            Console.WriteLine("Low: " + historicalData.low);
                            Console.WriteLine("High: " + historicalData.high);
                            Console.WriteLine("Change: " + historicalData.change);
                            Console.WriteLine("Change Percentage: " + historicalData.changePercent);
                        }
                    }                    
                }
            }
        }
    }


    public class HistoricalDataResponse
    {
        public string date { get; set; }
        public double open { get; set; }
        public double high { get; set; }
        public double low { get; set; }
        public double close { get; set; }
        public int volume { get; set; }
        public int unadjustedVolume { get; set; }
        public double change { get; set; }
        public double changePercent { get; set; }
        public double vwap { get; set; }
        public string label { get; set; }
        public double changeOverTime { 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.

5 Years Historical data Api

2 Years Historical data Api

1 Years Historical data Api


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