Skip to content

Commit 820c884

Browse files
authored
Merge pull request #10 from PyDataBlog:stock_splits
Completed draft of reference API
2 parents 424080a + 442e929 commit 820c884

File tree

4 files changed

+139
-12
lines changed

4 files changed

+139
-12
lines changed

src/PolygonIO.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ include("streaming_socket.jl")
1818

1919
######### Global export of user API ################
2020
export PolyOpts, tickers, ticker_types, ticker_details, ticker_details_vX,
21-
ticker_news, markets, locales
21+
ticker_news, markets, locales, stock_splits, stock_dividends,
22+
stock_financials, market_holidays, market_status, stock_exchanges,
23+
condition_mappings, crypto_exchanges
2224

2325

2426
end

src/reference_api.jl

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,24 +135,109 @@ function locales(opts::PolyOpts)
135135
end
136136

137137
############ Stock Splits ####################
138+
"""
139+
"""
140+
function stock_splits(opts::PolyOpts, stocksTicker::String)
141+
stock_splits_base_url = "https://api.polygon.io/v2/reference/splits/$stocksTicker"
142+
params = Dict("apiKey" => opts.api_key)
143+
request_json = HTTP.get(stock_splits_base_url, query=params).body |> JSON3.read
138144

145+
return request_json.results
146+
end
139147

140148
############ Stock Dividends ####################
149+
"""
150+
"""
151+
function stock_dividends(opts::PolyOpts, stocksTicker::String)
152+
stock_dividends_base_url = "https://api.polygon.io/v2/reference/dividends/$stocksTicker"
153+
params = Dict("apiKey" => opts.api_key)
141154

155+
request_json = HTTP.get(stock_dividends_base_url, query=params).body |> JSON3.read
156+
157+
if opts.sink === nothing
158+
return request_json.results
159+
else
160+
return request_json.results |> opts.sink
161+
end
162+
end
142163

143164
############ Stock Financials ####################
165+
"""
166+
"""
167+
function stock_financials(opts::PolyOpts, stocksTicker::String; limit=5, kwargs...)
168+
stock_financials_base_url = "https://api.polygon.io/v2/reference/financials/$stocksTicker"
169+
params = Dict(
170+
"apiKey" => opts.api_key,
171+
"limit" => limit
172+
)
173+
# Extract kwargs and add to params
174+
merge!(params, Dict(kwargs))
144175

176+
request_json = HTTP.get(stock_financials_base_url, query=params).body |> JSON3.read
177+
178+
if opts.sink === nothing
179+
return request_json.results
180+
else
181+
return request_json.results |> opts.sink
182+
end
183+
end
145184

146185
############ Market Holidays ####################
186+
"""
187+
"""
188+
function market_holidays(opts::PolyOpts)
189+
params = Dict("apiKey" => opts.api_key)
190+
request_json = HTTP.get(market_holidays_base_url, query=params).body |> JSON3.read
147191

192+
if opts.sink === nothing
193+
return request_json
194+
else
195+
return request_json |> opts.sink
196+
end
197+
end
148198

149199
############ Market Status ####################
200+
"""
201+
"""
202+
function market_status(opts::PolyOpts)
203+
params = Dict("apiKey" => opts.api_key)
204+
request_json = HTTP.get(market_status_base_url, query=params).body |> JSON3.read
150205

206+
return request_json
207+
end
151208

152209
############ Stock Exchanges ####################
210+
"""
211+
"""
212+
function stock_exchanges(opts::PolyOpts)
213+
params = Dict("apiKey" => opts.api_key)
214+
request_json = HTTP.get(stock_exchanges_base_url, query=params).body |> JSON3.read
153215

216+
return request_json
217+
end
154218

155219
############ Condition Mappings ####################
220+
"""
221+
"""
222+
function condition_mappings(opts::PolyOpts, tickertype="trades")
223+
condition_mappings_base_url = "https://api.polygon.io/v1/meta/conditions/$tickertype"
224+
params = Dict("apiKey" => opts.api_key)
225+
226+
request_json = HTTP.get(condition_mappings_base_url, query=params).body |> JSON3.read
227+
228+
return request_json
229+
end
156230

231+
############ Crypto Exchanges ####################
232+
"""
233+
"""
234+
function crypto_exchanges(opts::PolyOpts)
235+
params = Dict("apiKey" => opts.api_key)
236+
request_json = HTTP.get(crypto_exchanges_base_url, query=params).body |> JSON3.read
157237

158-
############ Crypto Exchanges ####################
238+
if opts.sink === nothing
239+
return request_json
240+
else
241+
return request_json |> opts.sink
242+
end
243+
end

src/utils.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,12 @@ ticker_new_base_url = "https://api.polygon.io/v2/reference/news"
66

77
markets_base_url = "https://api.polygon.io/v2/reference/markets"
88

9-
locales_base_url = "https://api.polygon.io/v2/reference/locales"
9+
locales_base_url = "https://api.polygon.io/v2/reference/locales"
10+
11+
market_holidays_base_url = "https://api.polygon.io/v1/marketstatus/upcoming"
12+
13+
market_status_base_url = "https://api.polygon.io/v1/marketstatus/now"
14+
15+
stock_exchanges_base_url = "https://api.polygon.io/v1/meta/exchanges"
16+
17+
crypto_exchanges_base_url = "https://api.polygon.io/v1/meta/crypto-exchanges"

test/runtests.jl

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,62 @@ const regular_opts = PolyOpts(API_KEY, nothing)
1313

1414
@testset "PolygonIO.jl" begin
1515
# tickets test
16-
@test tickers(tabular_opts, "bitcoin") |> size == (10, )
17-
@test tickers(regular_opts, "bitcoin") |> size == (10, )
16+
@test tickers(tabular_opts, "bitcoin") |> length == 10
17+
@test tickers(regular_opts, "bitcoin") |> length == 10
1818

1919
# ticker_types test
2020
@test ticker_types(tabular_opts) |> length == 2
2121
@test ticker_types(regular_opts) |> length == 2
2222

2323
# ticker_details test
24-
@test ticker_details(tabular_opts, "AAPL") |> size == (1, )
25-
@test ticker_details(regular_opts, "AAPL") |> length == 28
24+
@test ticker_details(tabular_opts, "AAPL") |> length == 1
25+
@test ticker_details(regular_opts, "AAPL") |> length >= 28
2626

2727
# ticker_details_vX next version test
28-
@test ticker_details_vX(tabular_opts, "AAPL", "2019-07-31") |> size == (1, )
28+
@test ticker_details_vX(tabular_opts, "AAPL", "2019-07-31") |> length == 1
2929
@test ticker_details_vX(regular_opts, "AAPL", "2019-07-31") |> length == 19
3030

3131
# ticker_news test
3232
@test ticker_news(tabular_opts, "AAPL") |> length == 10
3333
@test ticker_news(regular_opts, "AAPL") |> length == 10
3434

3535
# markets test
36-
@test markets(regular_opts) |> length == 7
37-
@test markets(tabular_opts) |> size == (7,)
36+
@test markets(regular_opts) |> length >= 7
37+
@test markets(tabular_opts) |> length >= 7
3838

3939
# locales test
40-
@test locales(regular_opts) |> size == (19,)
41-
@test locales(tabular_opts) |> size == (19,)
40+
@test locales(regular_opts) |> length >= 19
41+
@test locales(tabular_opts) |> length >= 19
42+
43+
# stock_splits test
44+
@test stock_splits(regular_opts, "AAPL") |> length >= 4
45+
@test stock_splits(tabular_opts, "AAPL") |> length >= 4
46+
47+
# stock_dividends test
48+
@test stock_dividends(regular_opts, "AAPL") |> length >= 65
49+
@test stock_dividends(tabular_opts, "AAPL") |> length >= 65
50+
51+
# stock_financials test
52+
@test stock_financials(regular_opts, "AAPL") |> length == 5
53+
@test stock_financials(tabular_opts, "AAPL") |> length == 5
54+
55+
# market_holidays test
56+
@test market_holidays(regular_opts) |> length >= 1
57+
@test market_holidays(tabular_opts) |> length >= 1
58+
59+
# market_status test
60+
@test market_status(regular_opts) |> length >= 6
61+
@test market_status(tabular_opts) |> length >= 6
62+
63+
# stock_exchanges test
64+
@test stock_exchanges(regular_opts) |> length >= 30
65+
@test stock_exchanges(tabular_opts) |> length >= 30
66+
67+
# condition_mappings test
68+
@test condition_mappings(regular_opts, "trades") |> length >= 1
69+
@test condition_mappings(tabular_opts, "quotes") |> length >= 1
70+
71+
# stock_exchanges test
72+
@test crypto_exchanges(regular_opts) |> length >= 5
73+
@test crypto_exchanges(tabular_opts) |> length >= 5
4274
end

0 commit comments

Comments
 (0)