Hilres.Yahoo.ApiClient
1.0.1
See the version list below for details.
dotnet add package Hilres.Yahoo.ApiClient --version 1.0.1
NuGet\Install-Package Hilres.Yahoo.ApiClient -Version 1.0.1
<PackageReference Include="Hilres.Yahoo.ApiClient" Version="1.0.1" />
paket add Hilres.Yahoo.ApiClient --version 1.0.1
#r "nuget: Hilres.Yahoo.ApiClient, 1.0.1"
// Install Hilres.Yahoo.ApiClient as a Cake Addin #addin nuget:?package=Hilres.Yahoo.ApiClient&version=1.0.1 // Install Hilres.Yahoo.ApiClient as a Cake Tool #tool nuget:?package=Hilres.Yahoo.ApiClient&version=1.0.1
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 =>
{
builder
.AddFilter("Microsoft", LogLevel.Warning)
.AddFilter("System", LogLevel.Warning)
.AddConsole();
});
ILogger logger = loggerFactory.CreateLogger<Program>();
logger.LogInformation("Start");
var client = new YahooClient(loggerFactory.CreateLogger<YahooClient>());
/* more code */
logger.LogInformation("End");
}
}
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)
Example:
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)
{
Console.WriteLine(item);
}
}
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)
Example:
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)
.ConfigureAwait(false);
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
Notes
Based on https://github.com/danh955/z016
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Microsoft.Extensions.Logging.Abstractions (>= 6.0.0)
- System.Linq.Async (>= 5.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.