Skip to content

Commit 4ef6f13

Browse files
committed
Added Short Interest and IPOs support
1 parent d9a3e39 commit 4ef6f13

File tree

4 files changed

+192
-0
lines changed

4 files changed

+192
-0
lines changed

examples/rest/stocks-ipos.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from polygon import RESTClient
2+
3+
# docs
4+
# https://polygon.io/docs/stocks/get_v1_reference_ipos
5+
6+
# client = RESTClient("XXXXXX") # hardcoded api_key is used
7+
client = RESTClient() # POLYGON_API_KEY environment variable is used
8+
9+
ipos = []
10+
for ipo in client.list_ipos(ticker="RDDT"):
11+
ipos.append(ipo)
12+
13+
print(ipos)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from polygon import RESTClient
2+
3+
# docs
4+
# https://polygon.io/docs/stocks/get_v1_reference_short-interest__identifierType___identifier
5+
6+
# client = RESTClient("XXXXXX") # hardcoded api_key is used
7+
client = RESTClient() # POLYGON_API_KEY environment variable is used
8+
9+
short_interest = []
10+
for si in client.list_short_interest(
11+
identifier="AMD",
12+
identifier_type="ticker",
13+
params={
14+
"date.gte": "2024-10-07",
15+
"date.lte": "2024-10-07",
16+
},
17+
limit=100
18+
):
19+
short_interest.append(si)
20+
21+
print(short_interest)

polygon/rest/models/tickers.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,89 @@ class TickerChangeResults:
253253
@staticmethod
254254
def from_dict(d):
255255
return TickerChangeResults(**d)
256+
257+
@modelclass
258+
class ShortInterest:
259+
"""
260+
Short Interest data for a specific identifier.
261+
"""
262+
263+
currency_code: Optional[str] = None
264+
date: Optional[str] = None
265+
isin: Optional[str] = None
266+
name: Optional[str] = None
267+
security_description: Optional[str] = None
268+
short_volume: Optional[int] = None
269+
short_volume_exempt: Optional[int] = None
270+
ticker: Optional[str] = None
271+
us_code: Optional[str] = None
272+
273+
@staticmethod
274+
def from_dict(d):
275+
return ShortInterest(
276+
currency_code=d.get("currency_code"),
277+
date=d.get("date"),
278+
isin=d.get("isin"),
279+
name=d.get("name"),
280+
security_description=d.get("security_description"),
281+
short_volume=d.get("short_volume"),
282+
short_volume_exempt=d.get("short_volume_exempt"),
283+
ticker=d.get("ticker"),
284+
us_code=d.get("us_code"),
285+
)
286+
287+
@modelclass
288+
class IPOListing:
289+
"""
290+
IPO Listing data.
291+
"""
292+
293+
currency_code: Optional[str] = None
294+
final_issue_price: Optional[float] = None
295+
highest_offer_price: Optional[float] = None
296+
ipo_status: Optional[str] = None
297+
isin: Optional[str] = None
298+
issue_end_date: Optional[str] = None
299+
issue_start_date: Optional[str] = None
300+
issuer_name: Optional[str] = None
301+
last_updated: Optional[str] = None
302+
listing_date: Optional[str] = None
303+
listing_price: Optional[float] = None
304+
lot_size: Optional[int] = None
305+
lowest_offer_price: Optional[float] = None
306+
max_shares_offered: Optional[int] = None
307+
min_shares_offered: Optional[int] = None
308+
primary_exchange: Optional[str] = None
309+
security_description: Optional[str] = None
310+
security_type: Optional[str] = None
311+
shares_outstanding: Optional[int] = None
312+
ticker: Optional[str] = None
313+
total_offer_size: Optional[float] = None
314+
us_code: Optional[str] = None
315+
316+
@staticmethod
317+
def from_dict(d):
318+
return IPOListing(
319+
currency_code=d.get("currency_code"),
320+
final_issue_price=d.get("final_issue_price"),
321+
highest_offer_price=d.get("highest_offer_price"),
322+
ipo_status=d.get("ipo_status"),
323+
isin=d.get("isin"),
324+
issue_end_date=d.get("issue_end_date"),
325+
issue_start_date=d.get("issue_start_date"),
326+
issuer_name=d.get("issuer_name"),
327+
last_updated=d.get("last_updated"),
328+
listing_date=d.get("listing_date"),
329+
listing_price=d.get("listing_price"),
330+
lot_size=d.get("lot_size"),
331+
lowest_offer_price=d.get("lowest_offer_price"),
332+
max_shares_offered=d.get("max_shares_offered"),
333+
min_shares_offered=d.get("min_shares_offered"),
334+
primary_exchange=d.get("primary_exchange"),
335+
security_description=d.get("security_description"),
336+
security_type=d.get("security_type"),
337+
shares_outstanding=d.get("shares_outstanding"),
338+
ticker=d.get("ticker"),
339+
total_offer_size=d.get("total_offer_size"),
340+
us_code=d.get("us_code"),
341+
)

polygon/rest/reference.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
SIP,
2323
Exchange,
2424
OptionsContract,
25+
ShortInterest,
26+
IPOListing,
2527
)
2628
from urllib3 import HTTPResponse
2729
from datetime import date
@@ -567,3 +569,73 @@ def list_options_contracts(
567569
deserializer=OptionsContract.from_dict,
568570
options=options,
569571
)
572+
573+
def list_short_interest(
574+
self,
575+
identifier: str,
576+
identifier_type: str = "ticker",
577+
date: Optional[str] = None,
578+
limit: Optional[int] = None,
579+
sort: Optional[Union[str, Sort]] = None,
580+
order: Optional[Union[str, Order]] = None,
581+
params: Optional[Dict[str, Any]] = None,
582+
raw: bool = False,
583+
options: Optional[RequestOptionBuilder] = None,
584+
) -> Union[List[ShortInterest], HTTPResponse]:
585+
"""
586+
Query for short interest data by Identifier and Date.
587+
588+
:param identifier: The case-sensitive identifier (e.g., "AAPL").
589+
:param identifier_type: The type of identifier ("ticker", "us_code", "isin").
590+
:param date: Either a date with the format YYYY-MM-DD or a nanosecond timestamp.
591+
:param params: Additional query parameters (e.g., date, order, limit, sort).
592+
:param raw: Return raw HTTPResponse instead of parsed data.
593+
:return: List of ShortInterest objects or HTTPResponse.
594+
"""
595+
url = f"/v1/reference/short-interest/{identifier_type}/{identifier}"
596+
597+
return self._paginate(
598+
path=url,
599+
params=self._get_params(self.list_short_interest, locals()),
600+
deserializer=ShortInterest.from_dict,
601+
raw=raw,
602+
result_key="results",
603+
options=options,
604+
)
605+
606+
def list_ipos(
607+
self,
608+
ticker: Optional[str] = None,
609+
us_code: Optional[str] = None,
610+
isin: Optional[str] = None,
611+
listing_date: Optional[str] = None,
612+
ipo_status: Optional[str] = None,
613+
limit: Optional[int] = None,
614+
sort: Optional[Union[str, Sort]] = None,
615+
order: Optional[Union[str, Order]] = None,
616+
params: Optional[Dict[str, Any]] = None,
617+
raw: bool = False,
618+
options: Optional[RequestOptionBuilder] = None,
619+
) -> Union[List[IPOListing], HTTPResponse]:
620+
"""
621+
Retrieve upcoming or historical IPOs.
622+
623+
:param ticker: Specify a case-sensitive ticker symbol. For example, AAPL represents Apple Inc.
624+
:param us_code: Specify a us_code. This is a unique nine-character alphanumeric code that identifies a North American financial security for the purposes of facilitating clearing and settlement of trades.
625+
:param isin: Specify an International Securities Identification Number (ISIN). This is a unique twelve-digit code that is assigned to every security issuance in the world.
626+
:param listing_date: Specify a listing date. This is the first trading date for the newly listed entity.
627+
:param ipo_status: Specify an IPO status.
628+
:param params: Query parameters (e.g., ticker, us_code, isin, listing_date, order, limit, sort).
629+
:param raw: Return raw HTTPResponse instead of parsed data.
630+
:return: List of IPOListing objects or HTTPResponse.
631+
"""
632+
url = "/v1/reference/ipos"
633+
634+
return self._paginate(
635+
path=url,
636+
params=self._get_params(self.list_ipos, locals()),
637+
deserializer=IPOListing.from_dict,
638+
raw=raw,
639+
result_key="results",
640+
options=options,
641+
)

0 commit comments

Comments
 (0)