karlwancl / yahoofinanceapi Goto Github PK
View Code? Open in Web Editor NEWA handy Yahoo! Finance api wrapper, based on .NET Standard 2.0
License: MIT License
A handy Yahoo! Finance api wrapper, based on .NET Standard 2.0
License: MIT License
Hello, I am looking at the sample code and I am seeing a reference to Yahoo. However, when I try to run the samples, I get the error 'Yahoo' Does not exist in the current context. I tried using the classes YahooQuotes
and YahooHistory
then I get the error that Symbols
does not exist in the current context.
Where are you getting the Yahoo class?
Request: support the latest versions of the dependencies, particularly Flurl.
I am getting the following error on Azure:
Flurl.Http.FlurlHttpException: Request to https://query1.finance.yahoo.com/v7/finance/download/MCD?period1=1436745600&period2=1499817600&interval=1d&events=history&crumb= failed with status code 401 (Unauthorized). at Flurl.Http.Configuration.FlurlMessageHandler.d__1.MoveNext() in C:\projects\flurl\src\Flurl.Http.Shared\Configuration\FlurlMessageHandler.cs:line 59 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Net.Http.HttpClient.d__58.MoveNext()
It works flawlessly for a day or two with requests made every few hours, then the above exception starts being thrown. It looks like the crumb parameter is empty? What could cause that?
A great project and one of the few projects these days that still actually work after Yahoo closed the formal API.
Thank you
Fig
Anyone else experiencing this issue ?
This call is failing with 500 cannot find server - Call failed with status code 500 (Cannot find server.): GET https://fc.yahoo.com
var response = await "https://fc.yahoo.com"
.AllowHttpStatus("502")
.AllowHttpStatus("404")
.WithHeader(userAgentKey, userAgentValue)
.GetAsync()
.ConfigureAwait(false);
When I install the newest version of flurl (2.4.2 flurl.http and 2.8.2 flurl), there is an exception in Yahoo.QueryAsync() where it says that it cannot find the assembly Flurl.Http 2.1.0.
Could not load file or assembly 'System.Net.Http, Version=4.1.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
latest is 4.3.3??
Hi,
I would like to retrieve the historical data but by hour and not by day
I thank you in advance
Hi
After updating my Flurl.Http NuGet packages from 3.4.2 to 4.0.2, I suddenly get a compile error saying "Error CS1503 Argument 2: cannot convert from 'System.Threading.CancellationToken' to 'System.Net.Http.HttpCompletionOption'" in methods like QueryAsync and InitAsync of the YahooSession class.
Any idea on how to fix?
Does his API give premarket data? I was not able to find it.
Does anyone know any other API's which offer premarket data?
Are you already working on a fix for this:
http://stackoverflow.com/questions/44015838/cant-download-data-from-yahoo-finance-using-quantmod-in-r
This repo has implemented something to work around it:
https://github.com/joshuaulrich/quantmod/commits/157_yahoo_502
Can you please convert it to v6. V6 works.
Hello,
I am trying use this library with .NET framework 4.6.1 but I am getting the error: "Could not load file or assembly 'System.Runtime.Serialization.Primitives, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified."
Observations:
I am trying with console apps and when I try with Console app .NET core, everything works
Everytime that I create one new console app(.NET framework 4.6.1) and try, I get the same error, but with different assembly
Thank you very much for the library, and sorry about my english :(
Feature request: Is there any way to get a list of available stock symbols?
Hi there,
Great Library
Allow for historical prices to pass in multiple stocks
It would be nice to be able to pass in a list of stocks for historical prices. Perhaps your api can then loop through the list and make each call (perhaps in parallel)
Invalid / NotFound
Firstly I realise you kinda addressed it with #7
I think from an api point of view, and to be consistent with await Yahoo.Symbols
, an error result should be sent back rather than an exception.
Unfortunately some of the data seems to got corrupted by Yahoo. If I download CSV file manually using the browser, corrupted data lines show as "yyyy-MM-dd,null,null,null,null,null,nulll", and they cause the formatting exceptions and failure in YahooFinanceApi. For example, this happened to me with symbols VAW and FSESX. Could it be possible to just place nulls in the affected list entries, to mimic the manual download?
Could there be the possibility that BeforeSplit and AfterSplit are mixed up?
Since last night, prices cannot be retrieved from Yahoo Finance.
The failure occurs in Yahoo - Quote.cs in the following method
public async Task<IReadOnlyDictionary<string, Security>> QueryAsync(CancellationToken token = default)
Below, the FlurlHttpException ex is caught.
try
{
data = await url
.WithCookie(YahooSession.Cookie.Name, YahooSession.Cookie.Value)
.GetAsync(token)
.ReceiveJson()
.ConfigureAwait(false);
}
catch (FlurlHttpException ex)
The message in ex contains:
ResponseMessage = {StatusCode: 429, ReasonPhrase: 'Too Many Requests'
Cannot use v 1.12 in a 4.7 .net project. Gives a message that some runtime serialization code it not available.
Might have something to do with the Name function in Helper and/or the slimsemaphore
Keep up the good work.
And thank you.
Fig
I'm sorry if this is a redundant or stupid question. However, I copied the code given in the README.md
file for getting historical data for a stock, yet the program did not display any data - rather, it simply terminated after the function Yahoo.GetHistoricalAsync()
.
Sorry again if this is a stupid question. I'm only a beginner and still trying to get the hang of coding...
This is the code by the way:
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}");
}
Hi there,
This is a question more than a bug, I'm wondering how I would detect when yahoo data is pretty much returning the wrong data, $0 price for multiple stocks.
I.e. I recently noticed that when I requested 100 stocks, the stock price was 0 on yahoo's end, is there something in the API that tells me if the data being requested isn't right? or do I just have to loop through each stock and check if the value is 0?
Hi
I have just started using this package, but came unstuck today because I had installed CsvHelper 15.0 with exception on
var history = await Yahoo.GetHistoricalAsync(symbol, new DateTime(2020, 1, 1), new DateTime(2020, 7, 1), Period.Daily);
The exception was:
**Exception: Method not found: 'Void CsvHelper.CsvReader..ctor(System.IO.TextReader)'.
Line: YahooFinanceApi
StackTrace: at YahooFinanceApi.Yahoo.<GetTicksAsync>d__5`1.MoveNext()
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
at YahooFinanceApi.Yahoo.GetTicksAsync[ITick](String symbol, Nullable`1 startTime, Nullable`1 endTime, Period period, ShowOption showOption, Func`2 instanceFunction, CancellationToken token)
at YahooFinanceApi.Yahoo.<GetHistoricalAsync>d__2.MoveNext()
I have downgraded the project now to CsvHelper 7.1.1 and the all to GetHistoricalAsync works.
The code changes (comment out code) I made in order to downgrade from CsvHelper 15.0 online documented examples were:
using (var csv = new CsvReader(reader /*, CultureInfo.InvariantCulture*/))
AutoMap(/*CultureInfo.InvariantCulture*/);
I hope the above clues assist in quickly updating YahooFinanceApi to support the latest CsvHelper package.
In the meantime, is there a better way forward?
Thanks
symbol = DOV
See #23
Hello guys,
What exactly the Dividend Date should return?
When I get the Dividend Date for MSFT, it returns this: "1591833600".
Thanks for your great work,
Looking forward to answering from you
I notice that a stock split like 3:1 (i.e. 3 for 1) is recorded as BeforeSplit=3, AfterSplit=1. Is this reversed?
Hi there,
Firstly great work with this project. Just wondering if there will be a 3.0.0 release?
Thanks
Yahoo seems terminated their free api service
Flurl.Http.FlurlHttpException occurred
HResult=0x80131500
Message=GET https://download.finance.yahoo.com/d/quotes.csv?s=AAPL%2BGOOG&f=l1ohgp failed with status code 999 (Request denied).
Response body:
Hi. Really nice to be able to get stock quotes.
Any way to get the exchange rate for some currencies like USD-to-CAD?
Getting historical data takes much longer than getting the historical data through postman. Is there any way of increasing the speed for this?
It is particularly obvious when querying for many symbols.
I can see that the latest version on NuGet is still 2.0.0. Can you push the latest version?
Hi there,
quick question. DividendDate is wrong even after converting it from unix.
let's make an example. If I call symbol "LAMR", the right ex-dividend date is 18-03-2021 while YahooFinanci API returns the long value 1617148800 equals to 30-03-2021 after FromUnixTimeMilliseconds NodaTime conversion.
Where I am wrong?
Many Thks for your help
Regards
LUCA
Refer to: karlwancl/Trady#5
I am getting too many requests when I hit this API Call
data = await url
.WithCookie(YahooSession.Cookie.Name, YahooSession.Cookie.Value)
.GetAsync(token)
.ReceiveJson()
.ConfigureAwait(false);
Anyone else seeing this?
Great Library, I was wondering if there is a limit to the amount of stocks you can request at once?
The reason I ask is sometimes I request 200 stocks and I get like 197 back, then other times it returns 196
I did another test where I would request 100 symbols, and most of the time I get 99 back and a couple of times it returned 100, all within the space of seconds of testing
I'm just wondering if there is limitation somehow?
UPDATE
I think the issue I'm facing is that yahoo sometimes returns "invalid / non strading" stocks with their results, other times it omits them.
https://au.finance.yahoo.com/quote/AIO.AX?p=AIO.AX
So from the above screenshot you can see that the stock returns 0 for ask / bid price. It's usually an indication that the stock might not be trading.
Just thought it would be good information for others who tend to see different results coming back
Hi
Anybody else experiencing a "Flurl.Http.FlurlHttpException : Call failed with status code 502 (Connection timed out): GET https://fc.yahoo.com" error since Dec. 4?
Anyone found a workaround?
Hi there
I want to use your library to collect intraday historic data about some stocks. But how can I find the DateTime of the price in the data that i'm receiving doing a Yahoo.Symbols request.
Thanks,
Jacob
Hi.
I'm writing a C# .NET MAUI application and tested it with using the package but also with using the source directly. Same result:
Works perfectly when I use it on the "Windows Machine" but gets back "Call failed with status code 403 (Forbidden)
GET https://query1.finance.yahoo.com/v1/test/getcrumb."
on my Android device.
Using simply
var quotes = await Yahoo.Symbols(mySymbol).Fields(
Field.RegularMarketOpen,
Field.RegularMarketDayHigh,
Field.RegularMarketDayLow,
Field.RegularMarketPrice,
Field.RegularMarketVolume,
Field.RegularMarketTime,
Field.Currency,
Field.Exchange
)
.QueryAsync();
Thanks for any hint.
The Yahoo Finance Quote API includes support for after hours pricing via the following fields:
postMarketChangePercent
postMarketTime
postMarketPrice
postMarketChange
I noticed in both Security.cs
and Fields.cs
, none of these are specified. I also noticed this line (https://github.com/lppkarl/YahooFinanceApi/blob/master/YahooFinanceApi/Security.cs#L16) that states Secure.cs
is automatically generated but I'm not sure how that process works considering it dropped off a few items.
Flurl.Http.FlurlHttpException: Call failed with status code 500 (Cannot find server.): GET https://fc.yahoo.com
Code
[TestMethod]
public async Task GetDailyData_Should_Work()
{
// 设置时间范围(过去1年)
var toDate = DateTime.UtcNow;
var fromDate = toDate.AddMonths(-1);
// 创建一个标的(BTC/USD)并请求历史数据
var symbol = "BTC-USD";
var candles = await Yahoo.GetHistoricalAsync(symbol, fromDate, toDate, Period.Daily); // Daily, Weekly, Monthly
// 访问OHLCV数据
foreach (var candle in candles)
{
Console.WriteLine($"Date: {candle.DateTime}, Open: {candle.Open}, High: {candle.High}, Low: {candle.Low}, Close: {candle.Close}, Volume: {candle.Volume}");
}
Assert.IsTrue(candles != null && candles.Any());
}
Each time I am using this library in a project targeting .NET Framework 4.6.2, it causes a crazy number of references to System.* assemblies to be added. My understanding is that this issue has been solved with .NET core 2.0. Could you look into upgrading YahooFinanceApi (and also Quandle.NET which I see you authored) for better support?
I'm using the following:
Yahoo.Symbols("AAPL", "TSLA", "AMC").Fields(Field.Symbol, Field.RegularMarketPrice).QueryAsync()
But randomly each of these will have empty RegularMarketPrice values causing a dictionary exception.
There are some stocks that were lightly traded in previous years, and on some days, they had zero volume, zero trades.
ex: DRIP -- June 2, 2015.
or YINN for many days in 2015.
Yahoo finance historical prices shows these days as entries with all zeros.
It seems that this library just omits these days, and its difficult to determine in code if missing days are a result of yahoo finance having bad data, or if its valid no trading for the day.
What do you think about replicating the zero entries for those dates in this library? I could do this in my own code, but others might have this issue as well, so might make more sense to fix it here.
Hi,
I use the code in the readme for historical prices and I get always this exception:
Call failed with status code 429 (Too Many Requests): GET https://query1.finance.yahoo.com/v1/test/getcrumb'
It seems strange to me, but I don't understand where I'm going wrong
Thank you
It's prompt error if I try to pass invalid ticker of stock
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.