diff --git a/src/PolygonIO.jl b/src/PolygonIO.jl index 9fc105c..8c09c32 100644 --- a/src/PolygonIO.jl +++ b/src/PolygonIO.jl @@ -17,6 +17,8 @@ include("streaming_socket.jl") ######### Global export of user API ################ -export PolyOpts, tickers, ticker_types, ticker_details, ticker_details_vX +export PolyOpts, tickers, ticker_types, ticker_details, ticker_details_vX, + ticker_news + end diff --git a/src/reference_api.jl b/src/reference_api.jl index 92b4111..992003c 100644 --- a/src/reference_api.jl +++ b/src/reference_api.jl @@ -78,7 +78,32 @@ function ticker_details_vX(opts::PolyOpts, ticker::String, date::String) end ############ Ticker News ####################### +""" +""" +function ticker_news(opts::PolyOpts, + ticker::String; + published_utc_gte="2021-04-26", + limit=10, + order="descending", + sort="published_utc", + kwargs...) + + params = Dict( + "apiKey" => opts.api_key, + "ticker" => ticker, + "published_utc.gte" => published_utc_gte, + "limit" => limit, + "order" => order, + "sort" => sort + ) + # Extract kwargs and add to params + merge!(params, Dict(kwargs)) + + request_json = HTTP.get(ticker_new_base_url, query=params).body |> JSON3.read + return request_json.results + +end ############ Markets #################### diff --git a/src/utils.jl b/src/utils.jl index 271abe0..4235e41 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -1,3 +1,5 @@ tickers_base_url = "https://api.polygon.io/v3/reference/tickers" ticker_types_base_url = "https://api.polygon.io/v2/reference/types" + +ticker_new_base_url = "https://api.polygon.io/v2/reference/news" \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 3832773..28e4408 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -27,4 +27,8 @@ const regular_opts = PolyOpts(API_KEY, nothing) # ticker_details_vX next version test @test ticker_details_vX(tabular_opts, "AAPL", "2019-07-31") |> size == (1, ) @test ticker_details_vX(regular_opts, "AAPL", "2019-07-31") |> length == 19 + + # ticker_news test + @test ticker_news(tabular_opts, "AAPL") |> length == 10 + @test ticker_news(regular_opts, "AAPL") |> length == 10 end