Coder Social home page Coder Social logo

Comments (12)

karlwancl avatar karlwancl commented on May 27, 2024

@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.

mayerwin avatar mayerwin commented on May 27, 2024

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.

karlwancl avatar karlwancl commented on May 27, 2024

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.

karlwancl avatar karlwancl commented on May 27, 2024

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.

mayerwin avatar mayerwin commented on May 27, 2024

Hi, thanks, can you update the package on nuget?

from yahoofinanceapi.

karlwancl avatar karlwancl commented on May 27, 2024

Updated

from yahoofinanceapi.

mayerwin avatar mayerwin commented on May 27, 2024

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.

karlwancl avatar karlwancl commented on May 27, 2024

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.

karlwancl avatar karlwancl commented on May 27, 2024

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.

mayerwin avatar mayerwin commented on May 27, 2024

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.

karlwancl avatar karlwancl commented on May 27, 2024

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.

mayerwin avatar mayerwin commented on May 27, 2024

Done, it works again, thanks.

from yahoofinanceapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.