From a08ddf04bb38e16930c7c679c2c7a118be0d5e82 Mon Sep 17 00:00:00 2001 From: snovum <142379411+snovum@users.noreply.github.com> Date: Thu, 31 Aug 2023 06:54:01 -0700 Subject: [PATCH] Update stock_time_series.jl (#64) 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. --- src/stock_time_series.jl | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/src/stock_time_series.jl b/src/stock_time_series.jl index 84983e6..5dfb559 100644 --- a/src/stock_time_series.jl +++ b/src/stock_time_series.jl @@ -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(?\d+)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)