Hilres.Yahoo.ApiClient 1.0.2

.NET 6.0
dotnet add package Hilres.Yahoo.ApiClient --version 1.0.2
NuGet\Install-Package Hilres.Yahoo.ApiClient -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Hilres.Yahoo.ApiClient" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Hilres.Yahoo.ApiClient --version 1.0.2
#r "nuget: Hilres.Yahoo.ApiClient, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Hilres.Yahoo.ApiClient as a Cake Addin
#addin nuget:?package=Hilres.Yahoo.ApiClient&version=1.0.2

// Install Hilres.Yahoo.ApiClient as a Cake Tool
#tool nuget:?package=Hilres.Yahoo.ApiClient&version=1.0.2

Get stock data from the unofficial Yahoo web API


This will access the unofficial Yahoo web API. There API may not be available in the future.


Using Hilres.Yahoo.ApiClient

There are two function that will retrieve the historical stock prices.

YahooClient class

This YahooClient class should be created only once when the application is started. The logger is optional.

public YahooClient(ILogger? logger = null)

Example using logging in a console appliction

using Hilres.Yahoo.ApiClient;

private static class Program
    private static async Task Main()
        using var loggerFactory = LoggerFactory.Create(builder =>
                .AddFilter("Microsoft", LogLevel.Warning)
                .AddFilter("System", LogLevel.Warning)
        ILogger logger = loggerFactory.CreateLogger<Program>();

        var client = new YahooClient(loggerFactory.CreateLogger<YahooClient>());

        /* more code */


GetPricesAsync function

This will retrieve a IEnumerable<YahooPrice> price list.

public async Task<YahooPricesResult> GetPricesAsync(
    string symbol,
    DateOnly? firstDate = null,
    DateOnly? lastDate = null,
    YahooInterval interval = YahooInterval.Daily,
    CancellationToken cancellationToken = default)


var client = new YahooClient();
var result = await client.GetPricesAsync("msft", new(2022, 1, 3), new(2022, 1, 8));

if (result.IsSuccessful)
    foreach (var item in result.Prices)

GetPricesParserAsync function

This will retrive a IAsyncEnumerable<YahooPriceParser> price list. YahooPriceParser is used to convert the data and is not an object to use. The IAsyncEnumerable can only be used once and then the connection is closed.

public async Task<YahooPricesParserResult> GetPricesParserAsync(
    string symbol,
    DateOnly? firstDate = null,
    DateOnly? lastDate = null,
    YahooInterval interval = YahooInterval.Daily,
    CancellationToken cancellationToken = default)


var parser = await client.GetPricesParserAsync("msft", new(2022, 1, 3), new(2022, 1, 8));
if (parser.IsSuccessful)
    var prices = await parser.Prices
            .Select(p => new MyPrice(p.Date, p.AdjClose, p.Volume))
            .ToDictionaryAsync(p => p.Date)

    Console.WriteLine(prices[new(2022, 1, 4)]);
    Console.WriteLine(prices[new(2022, 1, 6)]);

public record MyPrice(DateOnly Date, double? AdjClose, long? Volume);

The cool thing about GetPricesParserAsync is that it minimizes creating extra objects. In this case, the values are going directly into the dictionary. GetPricesAsync is a warper that calls GetPricesParserAsync


Based on https://github.com/danh955/z016

Product Versions
.NET net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 207 11/7/2022
1.0.1 297 3/17/2022