ellisvalentiner/AlphaVantage.jl

AlphaVantageResponse Conversion

Closed this issue · 5 comments

Hi, thanks for the great work on this package so far!

When it comes to functions for fundamental company data, I get responses of type "AlphaVantageResponse".

Examples:
AlphaVantage.company_overview("AAPL")
AlphaVantage.income_statement("AAPL")
AlphaVantage.earnings("AAPL")
AlphaVantage.sector_performance()

In all these examples, the response seems to be correct but not in a format I can use for further analysis. I'm sure a way to convert these into Dicts has already been developed in a previous version based on a code example I saw from last year.

Apologies if this is reiterating issue #23, it looks a bit different to me.

You can pipe it into either a Dict or DataFrame.

AlphaVantage.company_overview("AAPL") |> Dict

or

using DataFrames
AlphaVantage.company_overview("AAPL") |> DataFrame

Documentation is a bit lacking around the AlphvaVantageResponse so I'll see if I can make it easier to understand.

Thanks for using the package!

Thanks for the recommendation, Dean. Unfortunately, using either Dict and DataFrame on AlphaVantageResponse returns errors for me (AlphaVantage.jl v"1.6.0").

AlphaVantage.income_statement("AAPL") |> Dict
ERROR: ArgumentError: Dict(kv): kv needs to be an iterator of tuples or pairs
Stacktrace:
Dict(kv::AlphaVantageResponse) at ./dict.jl
|>(x::AlphaVantageResponse, f::Type{Dict}) at ./operators.jl

ERROR: MethodError: no method matching iterate(::AlphaVantageResponse) Closest candidates are: iterate(!Matched::Union{LinRange, StepRangeLen}) at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/base/range.jl:826 iterate(!Matched::Union{LinRange, StepRangeLen}, !Matched::Integer) at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/base/range.jl:826 iterate(!Matched::T) where T<:Union{Base.KeySet{<:Any, <:Dict}, Base.ValueIterator{<:Dict}} at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/base/dict.jl:695 ...

Stacktrace:
grow_to!(dest::Dict{Any, Any}, itr::AlphaVantageResponse) at ./dict.jl
dict_with_eltype(DT_apply::Base.var"#317#319", kv::AlphaVantageResponse, t::Type) at ./abstractdict.jl
Dict(kv::AlphaVantageResponse) at ./dict.jl
|>(x::AlphaVantageResponse, f::Type{Dict}) at ./operators.jl

Could this be a missing dependency?

Yeah my bad, I was in a stale REPL:

AlphaVantage.company_overview("AAPL", datatype = "json")

works on Julia 1.7 and 0.4.1 of AlphaVantage, that returns a Dict.

Thank you very much, works like a dream!

I should add that it is actually your code in "Fundamental Stock Data from AlphaVantage.jl" I was trying to replicate.

Looking forward to using this package more often. Cheers!

Post updated, thanks for letting me know!