Api to find stock's Quote based on its publicly traded stock symbol. IEX Trading api is a best an reliable, alternative to Yahoo Finance and Google Finance Api.
Consuming Stock's Quote Info - IEX Trading api using Postman:
Web Api Url: https://api.iextrading.com/1.0/stock/msft/quote
Api Response:
{ symbol: "MSFT", companyName: "Microsoft Corporation", primaryExchange: "Nasdaq Global Select", sector: "Technology", calculationPrice: "previousclose", open: 85.9, openTime: 1514471400195, close: 85.72, closeTime: 1514494800319, high: 86.05, low: 85.5, latestPrice: 85.54, latestSource: "Previous close", latestTime: "December 29, 2017", latestUpdate: 1514505600000, latestVolume: 18546416, iexRealtimePrice: null, iexRealtimeSize: null, iexLastUpdated: null, delayedPrice: 85.4, delayedPriceTime: 1514584729458, previousClose: 85.54, change: 0, changePercent: 0, iexMarketPercent: null, iexVolume: null, avgTotalVolume: 22912022, iexBidPrice: null, iexBidSize: null, iexAskPrice: null, iexAskSize: null, marketCap: 659906045280, peRatio: 28.42, week52High: 87.4999, week52Low: 61.95, ytdChange: 0 }
Create a console application
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>
Create a C# POCO class for storing Json Response.
public class CompanyInfoResponse { public string symbol { get; set; } public string companyName { get; set; } public string primaryExchange { get; set; } public string sector { get; set; } public string calculationPrice { get; set; } public double open { get; set; } public long openTime { get; set; } public double close { get; set; } public long closeTime { get; set; } public double high { get; set; } public double low { get; set; } public double latestPrice { get; set; } public string latestSource { get; set; } public string latestTime { get; set; } public long latestUpdate { get; set; } public int latestVolume { get; set; } public string iexRealtimePrice { get; set; } public string iexRealtimeSize { get; set; } public string iexLastUpdated { get; set; } public double delayedPrice { get; set; } public long delayedPriceTime { get; set; } public double previousClose { get; set; } public int change { get; set; } public int changePercent { get; set; } public string iexMarketPercent { get; set; } public string iexVolume { get; set; } public int avgTotalVolume { get; set; } public string iexBidPrice { get; set; } public string iexBidSize { get; set; } public string iexAskPrice { get; set; } public string iexAskSize { get; set; } public long marketCap { get; set; } public double peRatio { get; set; } public double week52High { get; set; } public double week52Low { get; set; } public int ytdChange { get; set; } }
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 CompaniesInfo { class Program { static void Main(string[] args) { var symbol = "msft"; var IEXTrading_API_PATH = "https://api.iextrading.com/1.0/stock/{0}/quote"; 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 companysInfo = response.Content.ReadAsAsync<CompanyInfoResponse>().GetAwaiter().GetResult(); if (companysInfo != null) { Console.WriteLine("Company Name: " + companysInfo.companyName); Console.WriteLine("Open: " + companysInfo.open); Console.WriteLine("Close: " + companysInfo.close); Console.WriteLine("Low: " + companysInfo.low); Console.WriteLine("High: " + companysInfo.high); Console.WriteLine("52 Week Low: " + companysInfo.week52Low); Console.WriteLine("52 Week High: " + companysInfo.week52High); } } } } } public class CompanyInfoResponse { public string symbol { get; set; } public string companyName { get; set; } public string primaryExchange { get; set; } public string sector { get; set; } public string calculationPrice { get; set; } public double open { get; set; } public long openTime { get; set; } public double close { get; set; } public long closeTime { get; set; } public double high { get; set; } public double low { get; set; } public double latestPrice { get; set; } public string latestSource { get; set; } public string latestTime { get; set; } public long latestUpdate { get; set; } public int latestVolume { get; set; } public string iexRealtimePrice { get; set; } public string iexRealtimeSize { get; set; } public string iexLastUpdated { get; set; } public double delayedPrice { get; set; } public long delayedPriceTime { get; set; } public double previousClose { get; set; } public int change { get; set; } public int changePercent { get; set; } public string iexMarketPercent { get; set; } public string iexVolume { get; set; } public int avgTotalVolume { get; set; } public string iexBidPrice { get; set; } public string iexBidSize { get; set; } public string iexAskPrice { get; set; } public string iexAskSize { get; set; } public long marketCap { get; set; } public double peRatio { get; set; } public double week52High { get; set; } public double week52Low { get; set; } public int ytdChange { 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.