diff --git a/src/PolygonIO.jl b/src/PolygonIO.jl index 62cf805..dc66315 100644 --- a/src/PolygonIO.jl +++ b/src/PolygonIO.jl @@ -17,6 +17,6 @@ include("streaming_socket.jl") ######### Global export of user API ################ -export tickers, PolyOpts +export PolyOpts, tickers, ticker_types end diff --git a/src/reference_api.jl b/src/reference_api.jl index 98b6666..ad26d13 100644 --- a/src/reference_api.jl +++ b/src/reference_api.jl @@ -28,11 +28,21 @@ function tickers(opts::PolyOpts, return request_json.results |> opts.sink end - end ############ Ticker Types #################### +""" +""" +function ticker_types(opts::PolyOpts) + params = Dict("apiKey" => opts.api_key) + request_json = HTTP.get(ticker_types_base_url, query=params).body |> JSON3.read + if opts.sink ≠ nothing + @warn "This endpoint does not support a tabular interface. Returning JSON instead of $(opts.sink)." + end + + return request_json.results +end ############ Tickers Details #################### diff --git a/src/utils.jl b/src/utils.jl index 94dbf75..bf70c1e 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -1 +1,3 @@ -tickers_base_url = "https://api.polygon.io/v3/reference/tickers" \ No newline at end of file +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 diff --git a/test/runtests.jl b/test/runtests.jl index 4f8f91a..85a9236 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,3 +1,4 @@ +using Test: length using ConfigEnv using PolygonIO using TypedTables @@ -7,9 +8,17 @@ using Test dotenv() const API_KEY = ENV["API_KEY"] +const tabular_opts = PolyOpts(API_KEY, Table) +const regular_ops = PolyOpts(API_KEY, nothing) + @testset "PolygonIO.jl" begin - # Write your tests here. - @test tickers(PolyOpts(API_KEY, Table), "bitcoin") |> size == (10, ) - @test tickers(PolyOpts(API_KEY, nothing), "bitcoin") |> size == (10, ) + # tickets test + @test tickers(tabular_opts, "bitcoin") |> size == (10, ) + @test tickers(regular_ops, "bitcoin") |> size == (10, ) + + # ticker_types test + @test ticker_types(tabular_opts) |> length == 2 + @test ticker_types(regular_ops) |> length == 2 + @test_logs (:warn, "This endpoint does not support a tabular interface. Returning JSON instead of $(tabular_opts.sink).") ticker_types(tabular_opts) end