From 5b32878bf17f9bf40d047e7afedee6b7908c020c Mon Sep 17 00:00:00 2001 From: PyDataBlog Date: Fri, 2 Jul 2021 01:31:35 +0200 Subject: [PATCH] Added markets & locales --- src/PolygonIO.jl | 2 +- src/reference_api.jl | 23 +++++++++++++++++++++++ src/utils.jl | 6 +++++- test/runtests.jl | 8 ++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/PolygonIO.jl b/src/PolygonIO.jl index 8c09c32..e494cf7 100644 --- a/src/PolygonIO.jl +++ b/src/PolygonIO.jl @@ -18,7 +18,7 @@ include("streaming_socket.jl") ######### Global export of user API ################ export PolyOpts, tickers, ticker_types, ticker_details, ticker_details_vX, - ticker_news + ticker_news, markets, locales end diff --git a/src/reference_api.jl b/src/reference_api.jl index 992003c..8d834a6 100644 --- a/src/reference_api.jl +++ b/src/reference_api.jl @@ -106,10 +106,33 @@ function ticker_news(opts::PolyOpts, end ############ Markets #################### +""" +""" +function markets(opts::PolyOpts) + params = Dict("apiKey" => opts.api_key) + request_json = HTTP.get(markets_base_url, query=params).body |> JSON3.read + + if opts.sink === nothing + return request_json.results + else + return request_json.results |> opts.sink + end +end ############ Locales #################### +""" +""" +function locales(opts::PolyOpts) + params = Dict("apiKey" => opts.api_key) + request_json = HTTP.get(locales_base_url, query=params).body |> JSON3.read + if opts.sink === nothing + return request_json.results + else + return request_json.results |> opts.sink + end +end ############ Stock Splits #################### diff --git a/src/utils.jl b/src/utils.jl index 4235e41..471b014 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -2,4 +2,8 @@ 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 +ticker_new_base_url = "https://api.polygon.io/v2/reference/news" + +markets_base_url = "https://api.polygon.io/v2/reference/markets" + +locales_base_url = "https://api.polygon.io/v2/reference/locales" \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 28e4408..14ede78 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -31,4 +31,12 @@ const regular_opts = PolyOpts(API_KEY, nothing) # ticker_news test @test ticker_news(tabular_opts, "AAPL") |> length == 10 @test ticker_news(regular_opts, "AAPL") |> length == 10 + + # markets test + @test markets(regular_opts) |> length == 7 + @test markets(tabular_opts) |> size == (7,) + + # locales test + @test locales(regular_opts) |> size == (19,) + @test locales(tabular_opts) |> size == (19,) end