Skip to content

Commit

Permalink
Update stock_time_series.jl (#64)
Browse files Browse the repository at this point in the history
According to the Alpha Vantage Documentation `time_series_intraday_extended` queries have now been folded into `time_series_intraday` queries via an added optional month parameter.  I tried to incorporate the optional parameters `month`, `extended_hours`, and `adjusted` by making the following changes.  1)  Adding the above parameters to the `time_series_intraday` function and defaulting the boolean parameters `extended_hours` and `adjusted` to `true` as per the API documentation.   2)  Adding an argcheck for the non boolean `month` parameter to ensure that months are entered in the required (YYYY-MM) format starting from 2000-01 which is when data is first available.  3) Adding the new parameters to the `params`dictionary.  No other alterations were made to the `time_series_intraday` function.    I  removed the `time_series_intraday_extended` function as it appears to have been deprecated. It no longer appears in the Alpha Vantage API documentation and did not appear to work when I tested it.   Thanks for reviewing the matter.
  • Loading branch information
snovum committed Aug 31, 2023
1 parent c301469 commit a08ddf0
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions src/stock_time_series.jl
Original file line number Diff line number Diff line change
@@ -1,34 +1,20 @@
function time_series_intraday_extended(symbol::String, interval::String="60min", slice::String="year1month1"; client = GLOBAL[], parser = "default")
@argcheck in(interval, ["1min", "5min", "15min", "30min", "60min"])
sliceMatch = match(r"year(?<year>\d+)month(?<month>\d+)", slice)
@argcheck !Compat.isnothing(sliceMatch)
@argcheck parse(Int, sliceMatch["year"]) > 0
@argcheck parse(Int, sliceMatch["year"]) < 3
@argcheck parse(Int, sliceMatch["month"]) > 0
@argcheck parse(Int, sliceMatch["month"]) < 13
params = Dict(
"function"=>"TIME_SERIES_INTRADAY_EXTENDED",
"symbol"=>symbol,
"interval"=>interval,
"slice"=>slice,
"apikey"=>key(client)
)
uri = _build_uri(client.scheme, client.host, "query", params)
data = retry(_get_request, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000))(uri)
p = _parser(parser, "csv")
return p(data)
end

function time_series_intraday(symbol::String, interval::String="1min"; client = GLOBAL[], outputsize::String="compact", datatype::Union{String, Nothing}=nothing, parser = "default")
function time_series_intraday(symbol::String, interval::String="1min"; client = GLOBAL[], outputsize::String="compact", datatype::Union{String, Nothing}=nothing, parser = "default", adjusted::Bool=true, extended_hours::Bool=true, month::Union{String, Nothing}=nothing)
@argcheck in(interval, ["1min", "5min", "15min", "30min", "60min"])
@argcheck in(outputsize, ["compact", "full"])
@argcheck in(datatype, ["json", "csv", nothing])
if month != nothing
@argcheck occursin(r"^\d{4}-(0[1-9]|1[0-2])$", month) # month must be in MMMM-YY format
@argcheck Date(month) >= Date("2000-01")
end
params = Dict(
"function"=>"TIME_SERIES_INTRADAY",
"symbol"=>symbol,
"interval"=>interval,
"outputsize"=>outputsize,
"datatype"=>datatype,
"adjusted"=>string(adjusted),
"extended_hours"=>string(extended_hours),
"month"=>month,
"apikey"=>key(client)
)
uri = _build_uri(client.scheme, client.host, "query", params)
Expand Down

0 comments on commit a08ddf0

Please sign in to comment.