Comments (12)
@mayerwin , thanks for your notification! It may take some time to study and implement the changes, it will be committed once i have completed.
from yahoofinanceapi.
Thanks for the fast commit, it works for a first request (e.g. await Yahoo.GetHistoricalAsync(ticker, data.MinDt.ToDateTime(), maxDt.ToDateTime(), YahooFinanceApi.Period.Daily)
), however the second (for a different ticker) fails with throwing an exception: "Value cannot be null.\r\nParameter name: Crumb is empty!"
at YahooFinanceApi.Yahoo.<GetResponseStreamAsync>d__13.MoveNext()
from yahoofinanceapi.
Oops, it seems yahoo returns empty crumb if there's already a session with the client rather than creating a new session.
Maybe a cache of the cookie/ HTTP client is needed for the case, but it may create problem when using multiple thread. Anyways, thanks for the test. I need more time to dig deep to the problem.
from yahoofinanceapi.
Hi @mayerwin , I have added cache for the web client to prevent empty crumb when doing second or later requests, locking mechanism is also added to ensure thread-safety.
Please help to test if the committed code is working for 2nd times onwards and in multithread environment, thanks for your help!
from yahoofinanceapi.
Hi, thanks, can you update the package on nuget?
from yahoofinanceapi.
Updated
from yahoofinanceapi.
ok, so I am not getting 502 errors anymore, however I tried multi-threading and got some exceptions:
System.AggregateException: One or more errors occurred. ---> System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.ValueCollection.Enumerator.MoveNext()
at Flurl.Http.FlurlClient.WriteRequestCookies(HttpRequestMessage request) in C:\projects\flurl\src\Flurl.Http.Shared\FlurlClient.cs:line 220
at Flurl.Http.FlurlClient.<SendAsync>d__28.MoveNext() in C:\projects\flurl\src\Flurl.Http.Shared\FlurlClient.cs:line 199
--- 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 Flurl.Http.HttpResponseMessageExtensions.<ReceiveStream>d__4.MoveNext() in C:\projects\flurl\src\Flurl.Http.Shared\HttpResponseMessageExtensions.cs:line 77
--- 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.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at YahooFinanceApi.Yahoo.<GetResponseStreamAsync>d__16.MoveNext()
--- 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.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at YahooFinanceApi.Yahoo.<GetHistoricalAsync>d__14.MoveNext()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
Here is the test code used:
Enumerable.Range(0, 100)
.AsParallel()
.WithDegreeOfParallelism(16)
.ForAll(i => {
try {
Yahoo.GetHistoricalAsync(ticker, minDtm, maxDtm, YahooFinanceApi.Period.Daily).Wait();
}
catch (Exception ex) {
Logger.Trace($"Failed: " + ex);
}
Logger.Trace($"Done: " + i);
});
from yahoofinanceapi.
Thanks for the test! I need some time to figure out the multithread issue. For the time being, please use the api in single-thread environment, thanks!
from yahoofinanceapi.
It seems the cached client changes some of its internal state when calling the web url, lock is used for each web call for temporary fix, may improve the implementation when time is available.
from yahoofinanceapi.
I am getting the following error since yesterday: "Request to https://finance.yahoo.com/d/quotes.csv?s=MCD&f=ohgl1v failed with status code 301 (Redirect)."
It is redirected to: 301: Permanent redirect to http://download.finance.yahoo.com/d/quotes.csv?s=MCD&f=ohgl1v (and works in the browser)
Can you update the domain (the fix seems simple)?
from yahoofinanceapi.
The redirect exception only happens when the project is targeting the old .NET framework, I'm not sure if it is a problem from the package Flurl or httpclient. Anyways, the fix is commited & nuget package is updated, please update your version accordingly, thanks
from yahoofinanceapi.
Done, it works again, thanks.
from yahoofinanceapi.
Related Issues (20)
- Download fundamentals for a ticker HOT 1
- YahooFinanceApi not compatible with CsvHelper V15 HOT 1
- Dividend Date HOT 1
- Exchange rate? HOT 1
- DividendDate issue HOT 1
- Empty dictionary? HOT 2
- stock split before after data is always zero HOT 4
- Can I retrieve historical data by hour?
- Exception: Failure to create client HOT 27
- Is 3.0.0-beta3 the final version?
- v7 API now breaks with "code":"Unauthorized","description":"Invalid Cookie" HOT 16
- Failed with status code 403 on Android HOT 1
- Premarket data HOT 1
- Error Too Many Requests HOT 6
- Failing with Status code 502 since Dec 4? HOT 14
- Flurl.Http dependencies issues HOT 1
- Call failed with status code 500 HOT 1
- FlurlHttpException with StatusCode: 429, ReasonPhrase: 'Too Many Requests' HOT 9
- Error code 500 (Cannot find server.): GET https://fc.yahoo.com HOT 2
- Stock split question
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yahoofinanceapi.