From 941c2f9f6f700d46b0e5242e6cd25693ed237db2 Mon Sep 17 00:00:00 2001 From: PyDataBlog Date: Wed, 30 Jun 2021 00:22:03 +0200 Subject: [PATCH 1/2] Added tickers_types --- src/PolygonIO.jl | 3 ++- src/reference_api.jl | 12 +++++++++++- src/utils.jl | 4 +++- test/runtests.jl | 15 ++++++++++++--- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/PolygonIO.jl b/src/PolygonIO.jl index 62cf805..f8878e1 100644 --- a/src/PolygonIO.jl +++ b/src/PolygonIO.jl @@ -1,6 +1,7 @@ module PolygonIO # Gloabl Imports +using HTTP: body using JSON3 using HTTP @@ -17,6 +18,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 From 833e9903da1ef3e8346d0aa7c7c03651f332c56e Mon Sep 17 00:00:00 2001 From: PyDataBlog Date: Wed, 30 Jun 2021 00:26:33 +0200 Subject: [PATCH 2/2] Corrected wrong import --- src/PolygonIO.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/PolygonIO.jl b/src/PolygonIO.jl index f8878e1..dc66315 100644 --- a/src/PolygonIO.jl +++ b/src/PolygonIO.jl @@ -1,7 +1,6 @@ module PolygonIO # Gloabl Imports -using HTTP: body using JSON3 using HTTP