1- import logging
2-
31import requests
42
53
64class RESTClient :
75 DEFAULT_HOST = "api.polygon.io"
86
9- def __init__ (self , auth_key : str , debug : bool = False ):
7+ def __init__ (self , auth_key ):
108 self .auth_key = auth_key
119 self .url = "https://" + self .DEFAULT_HOST
1210
1311 self ._session = requests .Session ()
1412 self ._session .params ["apiKey" ] = self .auth_key
1513
16- logging .basicConfig (level = logging .DEBUG if debug else None )
17-
18- def tickers (self , ** params ):
14+ def tickers (self , ** query_params ):
1915 endpoint = f"{ self .url } /v2/reference/tickers"
20- return self ._session .get (endpoint , params = params )
16+ return self ._session .get (endpoint , params = query_params )
2117
22- def ticker_types (self , ** params ):
23- endpoint = f"{ self .url } /v2/references /types"
24- return self ._session .get (endpoint , params = params )
18+ def ticker_types (self , ** query_params ):
19+ endpoint = f"{ self .url } /v2/reference /types"
20+ return self ._session .get (endpoint , params = query_params )
2521
26- def ticker_details (self , symbol , ** params ):
22+ def ticker_details (self , symbol , ** query_params ):
2723 endpoint = f"{ self .url } /v1/meta/symbols/{ symbol } /company"
28- return self ._session .get (endpoint , params = params )
24+ return self ._session .get (endpoint , params = query_params )
2925
30- def ticker_news (self , symbol , ** params ):
26+ def ticker_news (self , symbol , ** query_params ):
3127 endpoint = f"{ self .url } /v1/meta/symbols/{ symbol } /news"
32- return self ._session .get (endpoint , params = params )
28+ return self ._session .get (endpoint , params = query_params )
29+
30+ def markets (self , ** query_params ):
31+ endpoint = f"{ self .url } /v2/reference/markets"
32+ return self ._session .get (endpoint , params = query_params )
33+
34+ def locales (self , ** query_params ):
35+ endpoint = f"{ self .url } /v2/reference/locales"
36+ return self ._session .get (endpoint , params = query_params )
37+
38+ def stock_splits (self , symbol , ** query_params ):
39+ endpoint = f"{ self .url } /v2/reference/splits/{ symbol } "
40+ return self ._session .get (endpoint , params = query_params )
41+
42+ def stock_dividends (self , symbol , ** query_params ):
43+ endpoint = f"{ self .url } /v2/reference/dividends/{ symbol } "
44+ return self ._session .get (endpoint , params = query_params )
45+
46+ def stock_financials (self , symbol , ** query_params ):
47+ endpoint = f"{ self .url } /v2/reference/financials/{ symbol } "
48+ return self ._session .get (endpoint , params = query_params )
49+
50+ def market_status (self , ** query_params ):
51+ endpoint = f"{ self .url } /v1/marketstatus/now"
52+ return self ._session .get (endpoint , params = query_params )
53+
54+ def market_holidays (self , ** query_params ):
55+ endpoint = f"{ self .url } /v1/marketstatus/upcoming"
56+ return self ._session .get (endpoint , params = query_params )
57+
58+ def exchanges (self , ** query_params ):
59+ endpoint = f"{ self .url } /v1/meta/exchanges"
60+ return self ._session .get (endpoint , params = query_params )
61+
62+ def historic_trades (self , symbol , date , ** query_params ):
63+ endpoint = f"{ self .url } /v1/historic/trades/{ symbol } /{ date } "
64+ return self ._session .get (endpoint , params = query_params )
65+
66+ def v2_historic_trades (self , ticker , date , ** query_params ):
67+ endpoint = f"{ self .url } /v2/ticks/stocks/trades/{ ticker } /{ date } "
68+ return self ._session .get (endpoint , params = query_params )
69+
70+ def historic_quotes (self , symbol , date , ** query_params ):
71+ endpoint = f"{ self .url } /v1/historic/quotes/{ symbol } /{ date } "
72+ return self ._session .get (endpoint , params = query_params )
73+
74+ def v2_historic_nbbo_quotes (self , ticker , date , ** query_params ):
75+ endpoint = f"{ self .url } /v2/ticks/stocks/nbbo/{ ticker } /{ date } "
76+ return self ._session .get (endpoint , params = query_params )
77+
78+ def last_trade_for_a_symbol (self , symbol , ** query_params ):
79+ endpoint = f"{ self .url } /v1/last/stocks/{ symbol } "
80+ return self ._session .get (endpoint , params = query_params )
81+
82+ def last_quote_for_a_symbol (self , symbol , ** query_params ):
83+ endpoint = f"{ self .url } /v1/last_quote/stocks/{ symbol } "
84+ return self ._session .get (endpoint , params = query_params )
85+
86+ def daily_open_close (self , symbol , date , ** query_params ):
87+ endpoint = f"{ self .url } /v1/open-close/{ symbol } /{ date } "
88+ return self ._session .get (endpoint , params = query_params )
89+
90+ def condition_mappings (self , ticktype , ** query_params ):
91+ endpoint = f"{ self .url } /v1/meta/conditions/{ ticktype } "
92+ return self ._session .get (endpoint , params = query_params )
93+
94+ def snapshot_all_tickers (self , ** query_params ):
95+ endpoint = f"{ self .url } /v2/snapshot/locale/us/markets/stocks/tickers"
96+ return self ._session .get (endpoint , params = query_params )
97+
98+ def snapshot_single_ticker (self , ticker , ** query_params ):
99+ endpoint = f"{ self .url } /v2/snapshot/locale/us/markets/stocks/tickers/{ ticker } "
100+ return self ._session .get (endpoint , params = query_params )
101+
102+ def snapshot_gainers_losers (self , direction , ** query_params ):
103+ endpoint = f"{ self .url } /v2/snapshot/locale/us/markets/stocks/{ direction } "
104+ return self ._session .get (endpoint , params = query_params )
105+
106+ def previous_close (self , ticker , ** query_params ):
107+ endpoint = f"{ self .url } /v2/aggs/ticker/{ ticker } /prev"
108+ return self ._session .get (endpoint , params = query_params )
109+
110+ def aggregates (self , ticker , multiplier , timespan , from_ , to , ** query_params ):
111+ endpoint = f"{ self .url } /v2/aggs/ticker/{ ticker } /range/{ multiplier } /{ timespan } /{ from_ } /{ to } "
112+ return self ._session .get (endpoint , params = query_params )
113+
114+ def grouped_daily (self , locale , market , date , ** query_params ):
115+ endpoint = f"{ self .url } /v2/aggs/grouped/locale/{ locale } /market/{ market } /{ date } "
116+ return self ._session .get (endpoint , params = query_params )
117+
118+ def historic_forex_ticks (self , from_ , to , date , ** query_params ):
119+ endpoint = f"{ self .url } /v1/historic/forex/{ from_ } /{ to } /{ date } "
120+ return self ._session .get (endpoint , params = query_params )
121+
122+ def real_time_currency_conversion (self , from_ , to , ** query_params ):
123+ endpoint = f"{ self .url } /v1/conversion/{ from_ } /{ to } "
124+ return self ._session .get (endpoint , params = query_params )
125+
126+ def last_quote_for_a_currency_pair (self , from_ , to , ** query_params ):
127+ endpoint = f"{ self .url } /v1/last_quote/currencies/{ from_ } /{ to } "
128+ return self ._session .get (endpoint , params = query_params )
129+
130+ def snapshot_all_tickers (self , ** query_params ):
131+ endpoint = f"{ self .url } /v2/snapshot/locale/global/markets/forex/tickers"
132+ return self ._session .get (endpoint , params = query_params )
133+
134+ def snapshot_gainers_losers (self , direction , ** query_params ):
135+ endpoint = f"{ self .url } /v2/snapshot/locale/global/markets/forex/{ direction } "
136+ return self ._session .get (endpoint , params = query_params )
137+
138+ def crypto_exchanges (self , ** query_params ):
139+ endpoint = f"{ self .url } /v1/meta/crypto-exchanges"
140+ return self ._session .get (endpoint , params = query_params )
141+
142+ def last_trade_for_a_crypto_pair (self , from_ , to , ** query_params ):
143+ endpoint = f"{ self .url } /v1/last/crypto/{ from_ } /{ to } "
144+ return self ._session .get (endpoint , params = query_params )
145+
146+ def daily_open_close (self , from_ , to , date , ** query_params ):
147+ endpoint = f"{ self .url } /v1/open-close/crypto/{ from_ } /{ to } /{ date } "
148+ return self ._session .get (endpoint , params = query_params )
149+
150+ def historic_crypto_trades (self , from_ , to , date , ** query_params ):
151+ endpoint = f"{ self .url } /v1/historic/crypto/{ from_ } /{ to } /{ date } "
152+ return self ._session .get (endpoint , params = query_params )
153+
154+ def snapshot_all_tickers (self , ** query_params ):
155+ endpoint = f"{ self .url } /v2/snapshot/locale/global/markets/crypto/tickers"
156+ return self ._session .get (endpoint , params = query_params )
157+
158+ def snapshot_single_ticker (self , ticker , ** query_params ):
159+ endpoint = f"{ self .url } /v2/snapshot/locale/global/markets/crypto/tickers/{ ticker } "
160+ return self ._session .get (endpoint , params = query_params )
161+
162+ def snapshot_single_ticker_full_book_l2 (self , ticker , ** query_params ):
163+ endpoint = f"{ self .url } /v2/snapshot/locale/global/markets/crypto/tickers/{ ticker } /book"
164+ return self ._session .get (endpoint , params = query_params )
165+
166+ def snapshot_gainers_losers (self , direction , ** query_params ):
167+ endpoint = f"{ self .url } /v2/snapshot/locale/global/markets/crypto/{ direction } "
168+ return self ._session .get (endpoint , params = query_params )
0 commit comments