From 54203080eee43d1c624c954e008628eb8048b7e4 Mon Sep 17 00:00:00 2001 From: dm13450 Date: Fri, 29 Jan 2021 22:28:56 +0000 Subject: [PATCH] Add calendar functions --- src/AlphaVantage.jl | 4 +++- src/fundamentals.jl | 14 ++++++++++++++ src/utils.jl | 5 +++++ test/fundamentals_test.jl | 13 +++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/AlphaVantage.jl b/src/AlphaVantage.jl index 2a090b1..24a03f5 100644 --- a/src/AlphaVantage.jl +++ b/src/AlphaVantage.jl @@ -52,6 +52,8 @@ export balance_sheet, cash_flow, listing_status, - earnings + earnings, + earnings_calendar, + ipo_calendar end # module diff --git a/src/fundamentals.jl b/src/fundamentals.jl index b0e86f9..a696578 100644 --- a/src/fundamentals.jl +++ b/src/fundamentals.jl @@ -87,3 +87,17 @@ for (timeframe, f, value, dateKey) in FUNDAMENTAL_VALUES export $fname end end + + function earnings_calendar(horizon::Int64; client=GLOBAL[], parser = "default") + uri = _form_uri_head(client, "EARNINGS_CALENDAR") * "&horizon=$(horizon)month" * _form_uri_tail(client) + data = retry(_get_request, delays=Base.ExponentialBackOff(n=3, first_delay=4, max_delay=1000))(uri) + p = _parser(parser, "csv") + return p(data) + end + + function ipo_calendar(; client = GLOBAL[], parser = "default") + uri = _form_uri_head(client, "IPO_CALENDAR") * _form_uri_tail(client) + data = retry(_get_request, delays=Base.ExponentialBackOff(n=3, first_delay=4, max_delay=1000))(uri) + p = _parser(parser, "csv") + return p(data) + end \ No newline at end of file diff --git a/src/utils.jl b/src/utils.jl index bd2978c..e9df244 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -44,6 +44,11 @@ function _form_uri_tail(client::AVClient, outputsize, datatype) return a end +function _form_uri_tail(client::AVClient) + "&apikey=" * key(client) +end + + """ Internal function that helps forms the request uri """ diff --git a/test/fundamentals_test.jl b/test/fundamentals_test.jl index 5fa6be4..526bb3d 100644 --- a/test/fundamentals_test.jl +++ b/test/fundamentals_test.jl @@ -47,14 +47,27 @@ MAX_TESTS = parse(Int64, get(ENV, "MAX_TESTS", "1")) @testset "Default" begin data = listing_status() @test length(data) == 2 + sleep(TEST_SLEEP_TIME + 2*rand()) #as to not overload the API end @testset "Delisted and Date" begin data = listing_status(state = "delisted", date = "2020-12-17") @test length(data) == 2 + sleep(TEST_SLEEP_TIME + 2*rand()) #as to not overload the API end end + @testset "Earnings Calendar" begin + data = earnings_calendar(3) + @test length(data) == 2 + sleep(TEST_SLEEP_TIME + 2*rand()) #as to not overload the API + end + + @testset "IPO Calendar" begin + data = ipo_calendar() + @test length(data) == 2 + sleep(TEST_SLEEP_TIME + 2*rand()) #as to not overload the API + end end end # module