Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requesting prices outside available date range for ticker leads to unhelpful error #19

Closed
nilshg opened this issue Aug 13, 2024 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@nilshg
Copy link

nilshg commented Aug 13, 2024

Here's an extreme example:

julia> using YFinance, Dates

julia> get_prices("AAPL"; startdt = Date(1800), enddt = Date(1900))
┌ Error: Exception while generating log record in module YFinance at C:\Users\NGudat\.julia\packages\YFinance\drOZs\src\Prices.jl:180
│   exception =
│    KeyError: key :finance not found

I hit on this while getting prices for a whole list of tickers, where one of them happened to not have any prices available for the 6-month window I was looking at - took me a while to work out that key :finance not found means there aren't any prices for the requested dates.

This should probably be a more descriptive error.

@eohne
Copy link
Owner

eohne commented Aug 13, 2024

Found the issue. I need to make another if statement in the part where I throw the error after catching the error from the HTTP request. Normally if the call returns a 400 error I just pass on the error given from Yahoo directly - turns out that in this specific case the Yahoo error is stored in a different value in the returned JSON object.
Working on this now. I will still keep the throw_error flag to warn instead and returned an empty dict for this error also.

@eohne eohne self-assigned this Aug 13, 2024
@eohne eohne added the bug Something isn't working label Aug 13, 2024
@eohne
Copy link
Owner

eohne commented Aug 13, 2024

@nilshg would this work for you? This is basically the error message that is returned by Yahoo. I could parse out the UNIX dates and convert them but not sure that is needed.

julia> get_prices("aapl",startdt=Date(1800), enddt = Date(1900))
┌ Warning: Data doesn't exist for startDate = -5364662400, endDate = -2208988800 for aapl. An empy OrderedCollections.OrderedDict was returned!
└ @ Main c:\Users\elias\OneDrive\Julia\Packages\YFinance\src\Prices.jl:192
OrderedDict{Any, Any}()

julia> get_prices("aapl",startdt=Date(1800), enddt = Date(1900),throw_error=true)
ERROR: Data doesn't exist for startDate = -5364662400, endDate = -2208988800 for aapl
Stacktrace:
 [1] error(s::String)
   @ Base .\error.jl:35
 [2] get_prices(symbol::String; range::String, interval::String, startdt::Date, enddt::Date, prepost::Bool, autoadjust::Bool, timeout::Int64, throw_error::Bool, exchange_local_time::Bool, divsplits::Bool)
   @ Main c:\Users\elias\OneDrive\Julia\Packages\YFinance\src\Prices.jl:190
 [3] top-level scope
   @ REPL[2]:1

@nilshg
Copy link
Author

nilshg commented Aug 13, 2024

Looks good to me - parsing those UNIX dates seems like a fairly low effort way to make users' lives easier but not the end of the world if it stays like this (get ready for GitHub issues asking why the package is looking for prices on date -5 billion though :)).

@eohne
Copy link
Owner

eohne commented Aug 13, 2024

Fair enough just have to parse the dates out of the string etc

@eohne
Copy link
Owner

eohne commented Aug 13, 2024

Just hope parsing out the dates doesnt result in weird errors for edge cases.

julia> get_prices("aapl",startdt=Date(1800), enddt = Date(1900))
┌ Warning: Data doesn't exist for startDate = 1800-01-01T00:00:00, endDate = 1900-01-01T00:00:00 for aapl. An empy OrderedCollections.OrderedDict was returned!
└ @ Main c:\Users\elias\OneDrive\Julia\Packages\YFinance\src\Prices.jl:191
OrderedDict{Any, Any}()

julia> get_prices("aapl",startdt=Date(1800), enddt = Date(1900),throw_error=true)
ERROR: Data doesn't exist for startDate = 1800-01-01T00:00:00, endDate = 1900-01-01T00:00:00 for aapl
Stacktrace:
 [1] error(s::String)
   @ Base .\error.jl:35
 [2] get_prices(symbol::String; range::String, interval::String, startdt::Date, enddt::Date, prepost::Bool, autoadjust::Bool, timeout::Int64, throw_error::Bool, exchange_local_time::Bool, divsplits::Bool)
   @ Main c:\Users\elias\OneDrive\Julia\Packages\YFinance\src\Prices.jl:189
 [3] top-level scope
   @ REPL[12]:1

Edit: copied the unparsed version by mistake

@eohne eohne closed this as completed in 5806458 Aug 13, 2024
@eohne eohne mentioned this issue Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants