dshe / yahooquotesapi Goto Github PK
View Code? Open in Web Editor NEWRetrieves snapshot and historical quotes, dividends and splits, and modules from Yahoo Finance.
License: MIT License
Retrieves snapshot and historical quotes, dividends and splits, and modules from Yahoo Finance.
License: MIT License
I get an error accessing the pricehistory since recently:
Error (german):
System.Net.Http.HttpRequestException: 'Der angeforderte Name ist gültig, es wurden jedoch keine Daten des angeforderten Typs gefunden. (fc.yahoo.com:443)'
Error (englisch -> my translation):
The requested name is valid, but no data of the requested type was found
My code:
var dateNow = DateTime.Now.ToUniversalTime();
var dateTimeStart = dateNow.AddDays(-100);
var dateStart = Instant.FromDateTimeUtc(dateTimeStart);
YahooQuotes yahooQuotes = new YahooQuotesBuilder()
.WithHistoryStartDate(dateStart)
.WithPriceHistoryFrequency(frequency: Frequency.Daily)
.Build();
var security = yahooQuotes.GetAsync("MBG.DE", Histories.PriceHistory).GetAwaiter().GetResult();
Is anyone experiencing the same problem?
Thanks.
I recently found this really helpful API and was playing around with the examples given in the readme.
I was wondering if you could give me a little explanation on how to use the values given in the CurrencyHistory example.
I was expecting in the last example (see code below) that it would give me a decimal (or double as stated in your code) which symbolizes the conversion rates from USD to EUR. However, what I have found are pretty small numbers (Rate = 0.00010785159620362382 as of 24.03.2020) which I can not correlate to any information. Could you clarify what those rates are and if it is possible to use your API to get the current conversion rates from one currency to another?
Thank you for your help!
The code that I am referring to (taken from the readme file):
CurrencyHistory CurrencyHistory = new CurrencyHistory();
string currency = "EUR";
string baseCurrency = "USD";
List<RateTick> rates = await CurrencyHistory
.FromDate(new LocalDate(2010,1,1))
.GetRatesAsync(currency, baseCurrency);
Assert.True(rates[0].Rate > 0);
Historical Quote Streaming has stooped working with Exception "InvalidOperationException: YahooHistory: failure to reset HttpClient."
** Updated post **
Continue to Issues 12, 13.
#12
#13
When running Yahoo V6:
https://query2.finance.yahoo.com/v6/finance/quote?formatted=true&lang=en-US&symbols=AAPL
Getting the result:
{"finance":{"result":null,"error":{"code":"Not Found","description":"HTTP 404 Not Found"}}}
** looks like V6 is no longer available! that can explain why the latest component version stop working **
When running Yahoo V7:
https://query2.finance.yahoo.com/v7/finance/quote?formatted=true&lang=en-US&symbols=AAPL
Getting the result (as last week):
{"finance":{"result":null,"error":{"code":"Unauthorized","description":"Invalid Crumb"}}}
Using the latest version of the package (from last week) -
When running from C# getting the exception:
System.IO.InvalidDataException: quoteResponse
at YahooQuotesApi.YahooSnapshot.MakeRequest(Uri uri, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Snapshot\YahooSnapshot.cs:line 111
at YahooQuotesApi.YahooSnapshot.b__7_1(ValueTuple2 data, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Snapshot\YahooSnapshot.cs:line 66 at System.Threading.Tasks.Parallel.<>c__50
1.<b__50_0>d.MoveNext()
--- End of stack trace from previous location ---
at YahooQuotesApi.YahooSnapshot.GetElements(Symbol[] symbols, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Snapshot\YahooSnapshot.cs:line 65
at YahooQuotesApi.YahooSnapshot.Producer(Symbol[] symbols, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Snapshot\YahooSnapshot.cs:line 38
at YahooQuotesApi.SerialProducerCache2.Get(HashSet
1 keys, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Utilities\SerialProducerCache.cs:line 37
at YahooQuotesApi.YahooSnapshot.GetAsync(HashSet1 symbols, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Snapshot\YahooSnapshot.cs:line 31 at YahooQuotesApi.Quotes.GetSecuritiesAsync(HashSet
1 symbols, Histories historyFlags, Symbol historyBase, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Core\Quotes.cs:line 49
at YahooQuotesApi.Quotes.GetAsync(HashSet1 symbols, Histories historyFlags, Symbol historyBase, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Core\Quotes.cs:line 35 at YahooQuotesApi.YahooQuotes.GetAsync(IEnumerable
1 symbols, Histories historyFlags, String historyBase, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\YahooQuotes.cs
Can you please check/fix it?
Thanks!
I get an Exception only with the message "quoteResponse" no matter what i call.
For Example:
var dateNow = DateTime.Now.ToUniversalTime();
var dateTimeStart = dateNow.AddDays(-numberEntrys);
var dateStart = Instant.FromDateTimeUtc(dateTimeStart);
YahooQuotes yahooQuotes = new YahooQuotesBuilder()
.WithHistoryStartDate(dateStart)
.WithPriceHistoryFrequency(frequency: Frequency.Daily)
.Build();
Security security = yahooQuotes.GetAsync("TSLA", Histories.PriceHistory).GetAwaiter().GetResult();
or a simple call from the example:
YahooQuotes yahooQuotes = new YahooQuotesBuilder().Build();
Security? security = await yahooQuotes.GetAsync("AAPL");
Is there currently a problem with the API?
Thank you.
Hi there,
Thanks for a great library. Are there any plans to include other modules like assetProfile so you can get company address, information, website etc?
I got response message
"Response status code does not indicate success: 401 "
This library doesn't appear to support fundamental data from Yahoo Finance (https://query1.finance.yahoo.com/ws/fundamentals-timeseries/v1/finance/timeseries/{ticker}). Other Yahoo Finance libraries, like yfinance for python, supports this feature. I think it would be nice if it was added. I suck at coding so I can't add it however.
History stopped working for YahooFinanceApi and doesn't seem to work for this api either.
Hello, I've been using this for a few weeks as a replacement for another broken YahooFinance API that I used before. All the requests worked great yesterday giving me quotes and price history for any given symbol, but today I wasn't able to get anything...
I went ahead and dug into the issue and it is happening at the step where you make a request to https://fc.yahoo.com/ to obtain a cookie. I replicated this request in Postman and it was giving me 502 service unavailable. So there is a chance something else is happening. I googled around and did not see any kind of reference about these API URLs anywhere other than other 3rd party projects. Can you take a look and see what's going on?
Thanks a bunch!
Hello, I would like if you could show me an example of how I could obtain 30 minute candles for EURUSD for the last 7 days. ?
Thanks you
best regards
Damian
Hello, liked your project but what can cause this situation with "No cookies found" exception. My application have some GUI aspect and it's a small project. I have never ran into this issue with just a class library or console application. Is it not compatible with .NET MAUI?
No cookies found.
at YahooQuotesApi.CookieAndCrumb.GetCookieAndCrumb1(CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Core\CookieAndCrumb.cs:line 53
at YahooQuotesApi.CookieAndCrumb.Get(CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Core\CookieAndCrumb.cs:line 31
at YahooQuotesApi.YahooSnapshot.GetElements(List1 symbols, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Snapshot\YahooSnapshot.cs:line 61 at YahooQuotesApi.YahooSnapshot.Producer(List
1 symbols, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Snapshot\YahooSnapshot.cs:line 43
at YahooQuotesApi.SerialProducerCache2.<Get>d__5[[YahooQuotesApi.Symbol, YahooQuotesApi, Version=5.5.5.202, Culture=neutral, PublicKeyToken=null],[YahooQuotesApi.Security, YahooQuotesApi, Version=5.5.5.202, Culture=neutral, PublicKeyToken=null]].MoveNext() in C:\projects\yahooquotesapi\YahooQuotesApi\Utilities\SerialProducerCache.cs:line 37 at YahooQuotesApi.YahooSnapshot.GetAsync(HashSet
1 symbols, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Snapshot\YahooSnapshot.cs:line 33
at YahooQuotesApi.Quotes.GetSecuritiesAsync(HashSet1 symbols, Histories historyFlags, Symbol historyBase, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Core\Quotes.cs:line 49 at YahooQuotesApi.Quotes.GetAsync(HashSet
1 symbols, Histories historyFlags, Symbol historyBase, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Core\Quotes.cs:line 40
at YahooQuotesApi.YahooQuotes.GetAsync(IEnumerable`1 symbols, Histories historyFlags, String historyBase, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\YahooQuotes.cs:line 38
at YahooQuotesApi.YahooQuotes.GetAsync(String symbol, Histories historyFlags, String historyBase, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\YahooQuotes.cs:line 20
With the latest update I don't receive any future quotes anymore:
await yahoo.GetAsync($"6A=F", Histories.PriceHistory, "", cancellationToken)
This library doesn't support Yahoo Finance's live stream of price data using websockets, while some other Yahoo Finance libraries in other languages do. This would be very useful to have and is quite simple to add. If you want to test this API you can use Postman, mark it as websockets, the URL is wss://streamer.finance.yahoo.com/ and an example message you can send is {"subscribe":["^GSPC", "BTC-USD", "YM=F", "ES=F", "NQ=F", "^OMX", "INVE-B.ST", "EVO.ST"]} and then you will get back a continues stream of near-live stock price data.
I did a small code example of using this API in C#, including the necessary protobuf deserializing, which is in this repo.
Version 5.5.7.
Thrown when callingyahooQuotes.GetAsync
foreach (Equity equity in _Db.Equities.ToList(/* materialise */))
{
DateTime d = _Db.Prices.Where(z => z.Symbol == equity.Symbol).Select(z => z.Date).ToList().DefaultIfEmpty(DateTime.UtcNow.AddDays(-14)).Max();
YahooQuotes yahooQuotes = new YahooQuotesBuilder().WithHistoryStartDate(Instant.FromDateTimeUtc(d.ToUniversalTime())).Build();
_Logger.LogInformation($" Getting prices from {d:yyyy-MM-dd}.");
Security s = await yahooQuotes.GetAsync(equity.Symbol, Histories.PriceHistory);
Stak trace:
at YahooQuotesApi.CookieAndCrumb.<GetCookieAndCrumb1>d__6.MoveNext() in C:\projects\yahooquotesapi\YahooQuotesApi\Core\CookieAndCrumb.cs:line 37
at YahooQuotesApi.CookieAndCrumb.<Get>d__5.MoveNext() in C:\projects\yahooquotesapi\YahooQuotesApi\Core\CookieAndCrumb.cs:line 28
at YahooQuotesApi.YahooSnapshot.<GetElements>d__18.MoveNext() in C:\projects\yahooquotesapi\YahooQuotesApi\Snapshot\YahooSnapshot.cs:line 61
at YahooQuotesApi.YahooSnapshot.<Producer>d__17.MoveNext() in C:\projects\yahooquotesapi\YahooQuotesApi\Snapshot\YahooSnapshot.cs:line 43
at YahooQuotesApi.SerialProducerCache`2.<Get>d__5.MoveNext() in C:\projects\yahooquotesapi\YahooQuotesApi\Utilities\SerialProducerCache.cs:line 47
at YahooQuotesApi.YahooSnapshot.<GetAsync>d__16.MoveNext() in C:\projects\yahooquotesapi\YahooQuotesApi\Snapshot\YahooSnapshot.cs:line 33
at YahooQuotesApi.Quotes.<GetSecuritiesAsync>d__14.MoveNext() in C:\projects\yahooquotesapi\YahooQuotesApi\Core\Quotes.cs:line 49
at YahooQuotesApi.Quotes.<GetAsync>d__13.MoveNext() in C:\projects\yahooquotesapi\YahooQuotesApi\Core\Quotes.cs:line 35
at YahooQuotesApi.YahooQuotes.<GetAsync>d__6.MoveNext() in C:\projects\yahooquotesapi\YahooQuotesApi\YahooQuotes.cs:line 38
at YahooQuotesApi.YahooQuotes.<GetAsync>d__4.MoveNext() in C:\projects\yahooquotesapi\YahooQuotesApi\YahooQuotes.cs:line 20
at Rwb.Equities.App.ProgramAsync.<UpdatePricesAsync>d__7.MoveNext() in C:\Work\github\equities\Rwb.Equities.App\ProgramAsync.cs:line 77
Hi, first of al again thank you for this great library! After the EU cookies issue it worked great for the last few months but since yesterday I'm getting the following exception:
System.Text.Json.JsonReaderException: 'T' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.
at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)
at System.Text.Json.Utf8JsonReader.ConsumeValue(Byte marker)
at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte first)
at System.Text.Json.Utf8JsonReader.ReadSingleSegment()
at System.Text.Json.Utf8JsonReader.Read()
at System.Text.Json.JsonDocument.Parse(ReadOnlySpan`1 utf8JsonSpan, JsonReaderOptions readerOptions, MetadataDb& database, StackRowStack& stack)
at System.Text.Json.JsonDocument.Parse(ReadOnlyMemory`1 utf8Json, JsonReaderOptions readerOptions, Byte[] extraRentedArrayPoolBytes, PooledByteBufferWriter extraPooledByteBufferWriter)
at System.Text.Json.JsonDocument.ParseAsyncCore(Stream utf8Json, JsonDocumentOptions options, CancellationToken cancellationToken)
at YahooQuotesApi.YahooSnapshot.MakeRequest(Uri uri, List`1 cookie, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Snapshot\YahooSnapshot.cs:line 102
at YahooQuotesApi.YahooSnapshot.<>c__DisplayClass18_0.<<GetElements>b__1>d.MoveNext() in C:\projects\yahooquotesapi\YahooQuotesApi\Snapshot\YahooSnapshot.cs:line 75
This is the calling line:
Security security = await MyYahooQuotes.GetAsync(index, Histories.All) ?? throw new ArgumentException("Unknown symbol." + index);
...where index is the ticker I'm looking for. Does anyone have an idea what might be the cause for this? I'm completely clueless.
401 (Unauthorized).
Is the short interest on another API?
https://finance.yahoo.com/quote/TSLA/key-statistics?p=TSLA
Share Statistics
Avg Vol (3 month) 3 | 24.61M
Avg Vol (10 day) 3 | 27.42M
Shares Outstanding 5 | 1B
Implied Shares Outstanding 6 | N/A
Float 8 | 818.15M
% Held by Insiders 1 | 19.18%
% Held by Institutions 1 | 42.39%
Shares Short (Nov 15, 2021) 4 | 25.7M
Short Ratio (Nov 15, 2021) 4 | 0.76
Short % of Float (Nov 15, 2021) 4 | 3.15%
Short % of Shares Outstanding (Nov 15, 2021) 4 | 2.56%
Shares Short (prior month Oct 14, 2021) 4 | 30.34M
The project is very good, Thanks for all your hard work. It will help a lot of people.
I have one feature request for you if possible. Can you extend the API to download Company Financial Data like Balance Sheet, Income Statement & Cashflow. Its already available on Yahoo e.g.
https://finance.yahoo.com/quote/AAPL/balance-sheet?p=AAPL
This feature is not available in any existing project. Thanks again.
Start getting the following exception in the last hours:
Does anyone else getting it?
Looks similar to #28
Exception:
System.Text.Json.JsonReaderException: 'T' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.
at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan1 bytes) at System.Text.Json.Utf8JsonReader.ConsumeValue(Byte marker) at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte first) at System.Text.Json.Utf8JsonReader.ReadSingleSegment() at System.Text.Json.Utf8JsonReader.Read() at System.Text.Json.JsonDocument.Parse(ReadOnlySpan
1 utf8JsonSpan, JsonReaderOptions readerOptions, MetadataDb& database, StackRowStack& stack)
at System.Text.Json.JsonDocument.Parse(ReadOnlyMemory1 utf8Json, JsonReaderOptions readerOptions, Byte[] extraRentedArrayPoolBytes, PooledByteBufferWriter extraPooledByteBufferWriter) at System.Text.Json.JsonDocument.ParseAsyncCore(Stream utf8Json, JsonDocumentOptions options, CancellationToken cancellationToken) at YahooQuotesApi.YahooSnapshot.MakeRequest(Uri uri, IEnumerable
1 cookieValue, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Snapshot\YahooSnapshot.cs:line 127
at YahooQuotesApi.YahooSnapshot.<>c__DisplayClass8_0.<b__1>d.MoveNext() in C:\projects\yahooquotesapi\YahooQuotesApi\Snapshot\YahooSnapshot.cs:line 77
--- End of stack trace from previous location ---
at System.Threading.Tasks.Parallel.<>c__501.<<ForEachAsync>b__50_0>d.MoveNext() --- End of stack trace from previous location --- at YahooQuotesApi.YahooSnapshot.GetElements(Symbol[] symbols, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Snapshot\YahooSnapshot.cs:line 76 at YahooQuotesApi.YahooSnapshot.Producer(Symbol[] symbols, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Snapshot\YahooSnapshot.cs:line 45 at YahooQuotesApi.SerialProducerCache
2.Get(HashSet1 keys, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Utilities\SerialProducerCache.cs:line 37 at YahooQuotesApi.YahooSnapshot.GetAsync(HashSet
1 symbols, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Snapshot\YahooSnapshot.cs:line 35
at YahooQuotesApi.Quotes.GetSecuritiesAsync(HashSet1 symbols, Histories historyFlags, Symbol historyBase, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Core\Quotes.cs:line 49 at YahooQuotesApi.Quotes.GetAsync(HashSet
1 symbols, Histories historyFlags, Symbol historyBase, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Core\Quotes.cs:line 35
at YahooQuotesApi.YahooQuotes.GetAsync(IEnumerable1 symbols, Histories historyFlags, String historyBase, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\YahooQuotes.cs:line 38 at StocksAlerter.StocksDAL.GetStocksFromYahooAsync(IEnumerable
1 stocksSymbol, Nullable`1 stockDailyTradeSummaryStartUDateTime)
Hi there,
Firstly, great work on this project.
Is this an enhancement of https://github.com/karlwancl/YahooFinanceApi?
Questions:
I'm thinking of migrating to this project, since it has recently been updated, just wanting to know your thoughts thanks
Maybe the CookieAndCrumb expired?
What can we do to fix it?
The returned exception in .Net:
System.Net.Http.HttpRequestException: Response status code does not indicate success: 429 (Too Many Requests). at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode() at YahooQuotesApi.Crumb.YahooCrumb.GetCookieAndCrumb(CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Crumb\YahooCrumb.cs:line 72 at YahooQuotesApi.YahooSnapshot.GetElements(Symbol[] symbols, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Snapshot\YahooSnapshot.cs:line 80 at YahooQuotesApi.YahooSnapshot.Producer(Symbol[] symbols, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Snapshot\YahooSnapshot.cs:line 45 at YahooQuotesApi.SerialProducerCache2.Get(HashSet
1 keys, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Utilities\SerialProducerCache.cs:line 47 at YahooQuotesApi.YahooSnapshot.GetAsync(HashSet1 symbols, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Snapshot\YahooSnapshot.cs:line 36 at YahooQuotesApi.Quotes.GetSecuritiesAsync(HashSet
1 symbols, Histories historyFlags, Symbol historyBase, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Core\Quotes.cs:line 63 at YahooQuotesApi.Quotes.GetAsync(HashSet1 symbols, Histories historyFlags, Symbol historyBase, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\Core\Quotes.cs:line 42 at YahooQuotesApi.YahooQuotes.GetAsync(IEnumerable
1 symbols, Histories historyFlags, String historyBase, CancellationToken ct) in C:\projects\yahooquotesapi\YahooQuotesApi\YahooQuotes.cs
Can i also compile it for .NET 5.0, so i can create an UDF Assembly for SQL Server 2019
First of all, thanks a bunch for this API! I'm having a great time using it. However, there is one issue that I'm having: I can't seem to get any info for multiple tickers at the same time. Do you have any idea what could be causing the issue? This is (a simplified version of) the function that I'm using to call the API:
public async Task<Dictionary<string,Security>> GetStockPrices(string[] tickers)
{
Dictionary<string, Security> securities = await yahooQuotes.GetAsync(tickers);
}
However, securities never contains anything, the function always just skips to the next line. Do you have any idea why this could happen?
Just for extra info, this is how I'm calling the function. The application is a WinForms app running on 6.0
private void button1_Click(object sender, EventArgs e)
{
var priceInfo = GetStockPrices(new string[] { "TSLA","AAPL"});
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.