Skip to content

Commit 2dd1bcd

Browse files
Darcy-Lindeclickingbuttons
authored andcommitted
Tickers (#122)
1 parent 72366ef commit 2dd1bcd

File tree

4 files changed

+256
-6
lines changed

4 files changed

+256
-6
lines changed

polygon/rest/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from .aggs import AggsClient
22
from .trades import TradesClient
33
from .quotes import QuotesClient
4-
from .reference import MarketsClient
4+
from .reference import MarketsClient, TickersClient
55

66

7-
class RESTClient(AggsClient, TradesClient, QuotesClient, MarketsClient):
7+
class RESTClient(AggsClient, TradesClient, QuotesClient, MarketsClient, TickersClient):
88
pass

polygon/rest/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from .trades import *
33
from .quotes import *
44
from .markets import *
5+
from .tickers import *
56

67
from enum import Enum
78

@@ -10,7 +11,6 @@ class Sort(Enum):
1011
ASC = "asc"
1112
DESC = "desc"
1213

13-
1414
class Order(Enum):
1515
ASC = "asc"
1616
DESC = "desc"

polygon/rest/models/tickers.py

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
from typing import Optional, List
2+
from enum import Enum
3+
from dataclasses import dataclass
4+
5+
class Locale(Enum):
6+
US = "us"
7+
GLOBAL = "global"
8+
9+
class Market(Enum):
10+
STOCKS = "stocks"
11+
CRYPTO = "crypto"
12+
FX = "fx"
13+
14+
class AssetClass(Enum):
15+
STOCKS = "stocks"
16+
OPTIONS = "options"
17+
CRYPTO = "crypto"
18+
FX = "fx"
19+
20+
@dataclass
21+
class Address:
22+
address1: Optional[str] = None
23+
city: Optional[str] = None
24+
state: Optional[str] = None
25+
26+
@dataclass
27+
class Branding:
28+
icon_url: Optional[str] = None
29+
logo_url: Optional[str] = None
30+
31+
@dataclass
32+
class Publisher:
33+
favicon_url: Optional[str] = None
34+
homepage_url: Optional[str] = None
35+
logo_url: Optional[str] = None
36+
name: Optional[str] = None
37+
38+
39+
@dataclass
40+
class Ticker:
41+
"Ticker contains data for a specified ticker symbol."
42+
active: Optional[bool] = None
43+
cik: Optional[str] = None
44+
composite_figi: Optional[str] = None
45+
currency_name: Optional[str] = None
46+
delisted_utc: Optional[str] = None
47+
last_updated_utc: Optional[str] = None
48+
locale: Optional[Locale] = None
49+
market: Optional[Market] = None
50+
name: Optional[str] = None
51+
primary_exchange: Optional[str] = None
52+
share_class_figi: Optional[str] = None
53+
ticker: Optional[str] = None
54+
type: Optional[str] = None
55+
56+
@staticmethod
57+
def from_dict(d):
58+
return Ticker(**d)
59+
60+
@dataclass
61+
class TickerDetails:
62+
"TickerDetails contains data for a specified ticker symbol."
63+
active: Optional[bool] = None
64+
address: Optional[Address] = None
65+
branding: Optional[Branding] = None
66+
cik: Optional[str] = None
67+
composite_figi: Optional[str] = None
68+
currency_name: Optional[str] = None
69+
delisted_utc: Optional[str] = None
70+
description: Optional[str] = None
71+
homepage_url: Optional[str] = None
72+
list_date: Optional[str] = None
73+
locale: Optional[Locale] = None
74+
market: Optional[Market] = None
75+
market_cap: Optional[float] = None
76+
name: Optional[str] = None
77+
phone_number: Optional[str] = None
78+
primary_exchange: Optional[str] = None
79+
share_class_figi: Optional[str] = None
80+
share_class_shares_outstanding: Optional[int] = None
81+
sic_code: Optional[str] = None
82+
sic_description: Optional[str] = None
83+
ticker: Optional[str] = None
84+
total_employees: Optional[int] = None
85+
type: Optional[str] = None
86+
weighted_shares_outstanding: Optional[int] = None
87+
88+
@staticmethod
89+
def from_dict(d):
90+
return TickerDetails(**d)
91+
92+
@dataclass
93+
class TickerNews:
94+
"TickerDetails contains data for news articles relating to a stock ticker symbol."
95+
amp_url: Optional[str] = None
96+
article_url: Optional[str] = None
97+
author: Optional[str] = None
98+
description: Optional[str] = None
99+
id: Optional[str] = None
100+
image_url: Optional[str] = None
101+
keywords: Optional[List[str]] = None
102+
published_utc: Optional[str] = None
103+
publisher: Optional[Publisher] = None
104+
tickers: Optional[List[str]] = None
105+
title: Optional[str] = None
106+
107+
@staticmethod
108+
def from_dict(d):
109+
return TickerNews(**d)
110+
111+
@dataclass
112+
class TickerTypes:
113+
"TickerTypes contains data for ticker types."
114+
asset_class: Optional[AssetClass] = None
115+
code: Optional[str] = None
116+
description: Optional[str] = None
117+
locale: Optional[Locale] = None
118+
119+
@staticmethod
120+
def from_dict(d):
121+
return TickerNews(**d)

polygon/rest/reference.py

Lines changed: 132 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from .base import BaseClient
2-
from typing import Optional, Any, Dict, List, Union
3-
from .models import MarketHoliday, MarketStatus
2+
from typing import Optional, Any, Dict, List, Union, Iterator
3+
from .models import MarketHoliday, MarketStatus, Ticker, TickerDetails, TickerNews, TickerTypes, Sort, Order, AssetClass, Locale
44
from urllib3 import HTTPResponse
55

66
# https://polygon.io/docs/stocks
@@ -37,4 +37,133 @@ def get_market_status(
3737
"""
3838
url = "/v1/marketstatus/now"
3939

40-
return self._get(path=url, params=params, deserializer=MarketStatus.from_dict, raw=raw)
40+
return self._get(path=url, params=params, deserializer=MarketStatus.from_dict, raw=raw)
41+
42+
class TickersClient(BaseClient):
43+
def list_tickers(
44+
self,
45+
ticker: Optional[str] = None,
46+
ticker_lt: Optional[str] = None,
47+
ticker_lte: Optional[str] = None,
48+
ticker_gt: Optional[str] = None,
49+
ticker_gte: Optional[str] = None,
50+
type: Optional[str] = None,
51+
market: Optional[str] = None,
52+
exchange: Optional[str] = None,
53+
cusip: Optional[int] = None,
54+
cik: Optional[int] = None,
55+
date: Optional[str] = None,
56+
active: Optional[bool] = None,
57+
search: Optional[str] = None,
58+
limit: Optional[int] = None,
59+
sort: Optional[Union[str, Sort]] = None,
60+
order: Optional[Union[str, Order]] = None,
61+
params: Optional[Dict[str, Any]] = None,
62+
raw: bool = False,
63+
) -> Union[Iterator[Ticker], HTTPResponse]:
64+
"""
65+
Query all ticker symbols which are supported by Polygon.io. This API currently includes Stocks/Equities, Crypto, and Forex.
66+
67+
:param ticker: Specify a ticker symbol. Defaults to empty string which queries all tickers.
68+
:param ticker_lt: Timestamp less than
69+
:param ticker_lte: Ticker less than or equal to
70+
:param ticker_gt: Ticker greater than
71+
:param ticker_gte: Ticker greater than or equal to
72+
:param type: Specify the type of the tickers. Find the types that we support via our Ticker Types API. Defaults to empty string which queries all types.
73+
:param market: Filter by market type. By default all markets are included.
74+
:param exchange: Specify the primary exchange of the asset in the ISO code format. Find more information about the ISO codes at the ISO org website. Defaults to empty string which queries all exchanges.
75+
:param cusip: Specify the CUSIP code of the asset you want to search for. Find more information about CUSIP codes at their website. Defaults to empty string which queries all CUSIPs.
76+
:param cik: Specify the CIK of the asset you want to search for. Find more information about CIK codes at their website. Defaults to empty string which queries all CIKs.
77+
:param date: Specify a point in time to retrieve tickers available on that date. Defaults to the most recent available date.
78+
:param search: Search for terms within the ticker and/or company name.
79+
:param active: Specify if the tickers returned should be actively traded on the queried date. Default is true.
80+
:param limit: Limit the size of the response, default is 100 and max is 1000.
81+
:param sort: The field to sort the results on. Default is ticker. If the search query parameter is present, sort is ignored and results are ordered by relevance.
82+
:param order: The order to sort the results on. Default is asc (ascending).
83+
:param params: Any additional query params
84+
:param raw: Return raw object instead of results object
85+
:return: List of tickers
86+
:rtype: List[Ticker]
87+
"""
88+
url = "/v3/reference/tickers"
89+
90+
return self._paginate(
91+
path=url,
92+
params=self._get_params(self.list_tickers, locals()),
93+
raw=raw,
94+
deserializer=Ticker.from_dict,
95+
)
96+
97+
def get_ticker_details(
98+
self,
99+
ticker: Optional[str] = None,
100+
date: Optional[str] = None,
101+
params: Optional[Dict[str, Any]] = None,
102+
raw: bool = False,
103+
) -> Union[TickerDetails, HTTPResponse]:
104+
"""
105+
Get a single ticker supported by Polygon.io. This response will have detailed information about the ticker and the company behind it.
106+
107+
:param ticker: The ticker symbol of the asset.
108+
:param date: Specify a point in time to get information about the ticker available on that date. When retrieving information from SEC filings, we compare this date with the period of report date on the SEC filing.
109+
:param params: Any additional query params
110+
:param raw: Return raw object instead of results object
111+
:return: Ticker Details V3
112+
:rtype: TickerDetail
113+
"""
114+
url = f"/v3/reference/tickers/{ticker}"
115+
116+
return self._get(path=url, params=params, deserializer=TickerDetails.from_dict, raw=raw)
117+
118+
def get_ticker_news(
119+
self,
120+
ticker: Optional[str] = None,
121+
ticker_lt: Optional[str] = None,
122+
ticker_lte: Optional[str] = None,
123+
ticker_gt: Optional[str] = None,
124+
ticker_gte: Optional[str] = None,
125+
published_utc: Optional[str] = None,
126+
published_utc_lt: Optional[str] = None,
127+
published_utc_lte: Optional[str] = None,
128+
published_utc_gt: Optional[str] = None,
129+
published_utc_gte: Optional[str] = None,
130+
params: Optional[Dict[str, Any]] = None,
131+
raw: bool = False,
132+
) -> Union[TickerDetails, HTTPResponse]:
133+
"""
134+
Get the most recent news articles relating to a stock ticker symbol, including a summary of the article and a link to the original source.
135+
136+
:param ticker: Return results that contain this ticker.
137+
:param published_utc: Return results published on, before, or after this date.
138+
:param limit: Limit the number of results returned, default is 10 and max is 1000.
139+
:param sort: Sort field used for ordering.
140+
:param order: Order results based on the sort field.
141+
:param params: Any additional query params
142+
:param raw: Return raw object instead of results object
143+
:return: Ticker News
144+
:rtype: TickerNews
145+
"""
146+
url = "/v2/reference/news"
147+
148+
return self._get(path=url, params=params, deserializer=TickerNews.from_dict, raw=raw)
149+
150+
def get_ticker_types(
151+
self,
152+
asset_class: Optional[AssetClass] = None,
153+
locale: Optional[Locale] = None,
154+
params: Optional[Dict[str, Any]] = None,
155+
raw: bool = False,
156+
) -> Union[TickerTypes, HTTPResponse]:
157+
"""
158+
List all ticker types that Polygon.io has.
159+
160+
:param asset_class: Filter by asset class.
161+
:param locale: Filter by locale.
162+
:param params: Any additional query params
163+
:param raw: Return raw object instead of results object
164+
:return: Ticker Types
165+
:rtype: TickerTypes
166+
"""
167+
url = "/v3/reference/tickers/types"
168+
169+
return self._get(path=url, params=params, deserializer=TickerTypes.from_dict, raw=raw)

0 commit comments

Comments
 (0)