From fb5c41495397f19c73fda3bf1562007fb58406ad Mon Sep 17 00:00:00 2001 From: PyDataBlog Date: Thu, 1 Jul 2021 23:56:53 +0200 Subject: [PATCH] Added ticker_details_vX --- src/PolygonIO.jl | 2 +- src/reference_api.jl | 18 ++++++++++++++++++ src/utils.jl | 2 +- test/runtests.jl | 6 +++++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/PolygonIO.jl b/src/PolygonIO.jl index 848238c..9fc105c 100644 --- a/src/PolygonIO.jl +++ b/src/PolygonIO.jl @@ -17,6 +17,6 @@ include("streaming_socket.jl") ######### Global export of user API ################ -export PolyOpts, tickers, ticker_types, ticker_details +export PolyOpts, tickers, ticker_types, ticker_details, ticker_details_vX end diff --git a/src/reference_api.jl b/src/reference_api.jl index 1744e95..92b4111 100644 --- a/src/reference_api.jl +++ b/src/reference_api.jl @@ -57,7 +57,25 @@ function ticker_details(opts::PolyOpts, stocksTicker::String) end ############ Ticker Details vX #################### +""" +""" +function ticker_details_vX(opts::PolyOpts, ticker::String, date::String) + # TODO: Dispatch on proper Date type? + ticker_details_vX_base_url = "https://api.polygon.io/vX/reference/tickers/$ticker" + + params = Dict( + "apiKey" => opts.api_key, + "date" => date + ) + + request_json = HTTP.get(ticker_details_vX_base_url, query=params).body |> JSON3.read + if opts.sink === nothing + return request_json.results + else + return [request_json.results] |> opts.sink + end +end ############ Ticker News ####################### diff --git a/src/utils.jl b/src/utils.jl index bf70c1e..271abe0 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -1,3 +1,3 @@ tickers_base_url = "https://api.polygon.io/v3/reference/tickers" -ticker_types_base_url = "https://api.polygon.io/v2/reference/types" \ No newline at end of file +ticker_types_base_url = "https://api.polygon.io/v2/reference/types" diff --git a/test/runtests.jl b/test/runtests.jl index 02f0236..3832773 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,3 @@ -using Test: length using ConfigEnv using PolygonIO using TypedTables @@ -21,6 +20,11 @@ const regular_opts = PolyOpts(API_KEY, nothing) @test ticker_types(tabular_opts) |> length == 2 @test ticker_types(regular_opts) |> length == 2 + # ticker_details test @test ticker_details(tabular_opts, "AAPL") |> size == (1, ) @test ticker_details(regular_opts, "AAPL") |> length == 28 + + # 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 end