A handy Yahoo! Finance api wrapper, based on .NET Standard 2.0
- Get quotes
- Get historical data
- Get dividend data
- Get stock split data
This library is intended for personal use only, any improper use of this library is not recommended.
For traditional .NET framework user, if you find a "System.Runtime.Serialization.Primitives" missing exception is thrown when using this library, you have to install the missing package manually as nuget does not auto install this reference for you (Bugged?)
- Removed timezone support
- All api call now reads and returns datetime in EST instead of local timezone (Thanks for PR from @dshe)
- Removed ascending, leaveZeroWhenInvalid parameter in historical api call (Thanks for PR from @dshe)
- IgnoreEmptyRows property in replacement with the original leaveZeroIfInvalid parameter (Thanks for PR from @dshe)
- .NET Core 2.0
- .NET framework 4.6.1 or above
- Xamarin.iOS
- Xamarin.Android
- Universal Windows Platform
You can find the package through Nuget
PM> Install-Package YahooFinanceApi
using YahooFinanceApi;
var quotes = await Yahoo.Symbol("AAPL", "GOOG").Tag(Tag.LastTradePriceOnly, Tag.Open, Tag.DaysHigh, Tag.DaysLow, Tag.PreviousClose).GetAsync();
var aapl = quotes["AAPL"];
var price = aapl[Tag.LastTradePriceOnly];
// Sometimes, yahoo returns broken rows for historical calls, you could decide if these invalid rows is ignored or not by the following statement
Yahoo.IgnoreEmptyRows = true;
// You should be able to query data from various markets including US, HK, TW
// The startTime & endTime here defaults to EST timezone
var history = await Yahoo.GetHistoricalAsync("AAPL", new DateTime(2016, 1, 1), new DateTime(2016, 7, 1), Period.Daily);
foreach (var candle in history)
{
Console.WriteLine($"DateTime: {candle.DateTime}, Open: {candle.Open}, High: {candle.High}, Low: {candle.Low}, Close: {candle.Close}, Volume: {candle.Volume}, AdjustedClose: {candle.AdjustedClose}");
}
// You should be able to query data from various markets including US, HK, TW
var dividends = await Yahoo.GetDividendsAsync("AAPL", new DateTime(2016, 1, 1), new DateTime(2016, 7, 1));
foreach (var candle in dividends)
{
Console.WriteLine($"DateTime: {candle.DateTime}, Dividend: {candle.Dividend}");
}
var splits = await Yahoo.GetSplitsAsync("AAPL", new DateTime(2014, 6, 8), new DateTime(2014, 6, 10));
foreach (var s in splits)
{
Console.WriteLine($"DateTime: {s.DateTime}, AfterSplit: {s.AfterSplit}, BeforeSplit: {s.BeforeSplit}");
}