Streaming quotes from Yahoo Finance.
- .NET 8.0 library
- simple and intuitive API
- fault-tolerant
- dependencies: protobuf-net
- note that data is available only when the particular market is open
PM> Install-Package YahooQuotesObservable
using System.Reactive.Linq;
using YahooQuotesObservable;
// Create the observable.
IObservable<PricingData> observable = YahooQuotes.CreateObservable(["AAPL", "EURUSD=X"]);
// Subscribe to the observable.
IDisposable subscription = observable.Subscribe(pricingData =>
{
Console.Write($"Id: {pricingData.Id}, Price: {pricingData.Price}, Time: {pricingData.Time.ToInstant()}");
});
await Task.Delay(TimeSpan.FromSeconds(10));
// Unsubscribe from the observable.
subscription.Dispose();
string symbol = "EURUSD=X";
// Create the observable.
IObservable<PricingData> observable = YahooQuotes.CreateObservable(symbol);
// Subscribe to the observable, wait to receive the first output, then unsubscribe.
PricingData pricingData = await observable.FirstAsync().Timeout(TimeSpan.FromSeconds(10));
Assert.Equal(symbol, pricingData.Id);