Skip to content

Commit 4057f24

Browse files
Darcy-Lindeclickingbuttons
authored andcommitted
Tickers tests (#133)
1 parent 9db0beb commit 4057f24

File tree

4 files changed

+228
-3
lines changed

4 files changed

+228
-3
lines changed

polygon/rest/models/tickers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class Ticker:
3131
cik: Optional[str] = None
3232
composite_figi: Optional[str] = None
3333
currency_name: Optional[str] = None
34+
currency_symbol: Optional[str] = None
35+
base_currency_symbol: Optional[str] = None
36+
base_currency_name: Optional[str] = None
3437
delisted_utc: Optional[str] = None
3538
last_updated_utc: Optional[str] = None
3639
locale: Optional[Locale] = None
@@ -57,6 +60,7 @@ class TickerDetails:
5760
currency_name: Optional[str] = None
5861
delisted_utc: Optional[str] = None
5962
description: Optional[str] = None
63+
ticker_root: Optional[str] = None
6064
homepage_url: Optional[str] = None
6165
list_date: Optional[str] = None
6266
locale: Optional[Locale] = None
@@ -109,4 +113,4 @@ class TickerTypes:
109113

110114
@staticmethod
111115
def from_dict(d):
112-
return TickerNews(**d)
116+
return TickerTypes(**d)

polygon/rest/reference.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def get_ticker_types(
176176
locale: Optional[Union[str, Locale]] = None,
177177
params: Optional[Dict[str, Any]] = None,
178178
raw: bool = False,
179-
) -> Union[TickerTypes, HTTPResponse]:
179+
) -> Union[List[TickerTypes], HTTPResponse]:
180180
"""
181181
List all ticker types that Polygon.io has.
182182
@@ -189,7 +189,11 @@ def get_ticker_types(
189189
url = "/v3/reference/tickers/types"
190190

191191
return self._get(
192-
path=url, params=params, deserializer=TickerTypes.from_dict, raw=raw
192+
path=url,
193+
params=params,
194+
deserializer=TickerTypes.from_dict,
195+
raw=raw,
196+
result_key="results",
193197
)
194198

195199

tests/mocks.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,33 @@
1919
"/v2/aggs/ticker/AAPL/prev",
2020
'{"ticker":"AAPL","queryCount":1,"resultsCount":1,"adjusted":true,"results":[{"T":"AAPL","v":9.5595226e+07,"vw":158.6074,"o":162.25,"c":156.8,"h":162.34,"l":156.72,"t":1651003200000,"n":899965}],"status":"OK","request_id":"5e5378d5ecaf3df794bb52e45d015d2e","count":1}',
2121
),
22+
(
23+
"/v3/reference/tickers",
24+
'{"results":[{"ticker":"A","name":"Agilent Technologies Inc.","market":"stocks","locale":"us","primary_exchange":"XNYS","type":"CS","active":true,"currency_name":"usd","cik":"0001090872","composite_figi":"BBG000C2V3D6","share_class_figi":"BBG001SCTQY4","last_updated_utc":"2022-04-27T00:00:00Z"},{"ticker":"AA","name":"Alcoa Corporation","market":"stocks","locale":"us","primary_exchange":"XNYS","type":"CS","active":true,"currency_name":"usd","cik":"0001675149","composite_figi":"BBG00B3T3HD3","share_class_figi":"BBG00B3T3HF1","last_updated_utc":"2022-04-27T00:00:00Z"}],"status":"OK","request_id":"37089bb3b4ef99a796cdc82ff971e447","count":2,"next_url":"https://api.polygon.io/v3/reference/tickers?cursor=YWN0aXZlPXRydWUmZGF0ZT0yMDIyLTA0LTI3JmxpbWl0PTImb3JkZXI9YXNjJnBhZ2VfbWFya2VyPUFBJTdDZjEyMmJjYmY4YWQwNzRmZmJlMTZmNjkxOWQ0ZDc3NjZlMzA3MWNmNmU1Nzg3OGE0OGU1NjQ1YzQyM2U3NzJhOSZzb3J0PXRpY2tlcg"}',
25+
),
26+
(
27+
"/v3/reference/tickers?cursor=YWN0aXZlPXRydWUmZGF0ZT0yMDIyLTA0LTI3JmxpbWl0PTImb3JkZXI9YXNjJnBhZ2VfbWFya2VyPUFBJTdDZjEyMmJjYmY4YWQwNzRmZmJlMTZmNjkxOWQ0ZDc3NjZlMzA3MWNmNmU1Nzg3OGE0OGU1NjQ1YzQyM2U3NzJhOSZzb3J0PXRpY2tlcg",
28+
'{"results":[{"ticker":"AAA","name":"AAF First Priority CLO Bond ETF","market":"stocks","locale":"us","primary_exchange":"ARCX","type":"ETF","active":true,"currency_name":"usd","composite_figi":"BBG00X5FSP48","share_class_figi":"BBG00X5FSPZ4","last_updated_utc":"2022-04-27T00:00:00Z"},{"ticker":"AAAU","name":"Goldman Sachs Physical Gold ETF Shares","market":"stocks","locale":"us","primary_exchange":"BATS","type":"ETF","active":true,"currency_name":"usd","cik":"0001708646","composite_figi":"BBG00LPXX872","share_class_figi":"BBG00LPXX8Z1","last_updated_utc":"2022-04-27T00:00:00Z"}],"status":"OK","request_id":"40d60d83fa0628503b4d13387b7bde2a","count":2}',
29+
),
30+
(
31+
"/v3/reference/tickers/AAPL",
32+
'{"ticker":"AAPL","name":"Apple Inc.","market":"stocks","locale":"us","primary_exchange":"XNAS","type":"CS","active":true,"currency_name":"usd","cik":"0000320193","composite_figi":"BBG000B9XRY4","share_class_figi":"BBG001S5N8V8","market_cap":2.6714924917e+12,"phone_number":"(408) 996-1010","address":{"address1":"ONE APPLE PARK WAY","city":"CUPERTINO","state":"CA","postal_code":"95014"},"description":"Apple designs a wide variety of consumer electronic devices, including smartphones (iPhone), tablets (iPad), PCs (Mac), smartwatches (Apple Watch), AirPods, and TV boxes (Apple TV), among others. The iPhone makes up the majority of Apples total revenue. In addition, Apple offers its customers a variety of services such as Apple Music, iCloud, Apple Care, Apple TV+, Apple Arcade, Apple Card, and Apple Pay, among others. Apples products run internally developed software and semiconductors, and the firm is well known for its integration of hardware, software and services. Apples products are distributed online as well as through company-owned stores and third-party retailers. The company generates roughly 40 of its revenue from the Americas, with the remainder earned internationally.","sic_code":"3571","sic_description":"ELECTRONIC COMPUTERS","ticker_root":"AAPL","homepage_url":"https://www.apple.com","total_employees":154000,"list_date":"1980-12-12","branding":{"logo_url":"https://api.polygon.io/v1/reference/company-branding/d3d3LmFwcGxlLmNvbQ/images/2022-02-01_logo.svg","icon_url":"https://api.polygon.io/v1/reference/company-branding/d3d3LmFwcGxlLmNvbQ/images/2022-02-01_icon.png"},"share_class_shares_outstanding":16319440000,"weighted_shares_outstanding":16319441000}',
33+
),
34+
(
35+
"/v2/reference/news",
36+
'{"results":[{"id":"JeJEhAVoKaqJ2zF9nzQYMg07UlEeWlis6Dsop33TPQY","publisher":{"name":"MarketWatch","homepage_url":"https://www.marketwatch.com/","logo_url":"https://s3.polygon.io/public/assets/news/logos/marketwatch.svg","favicon_url":"https://s3.polygon.io/public/assets/news/favicons/marketwatch.ico"},"title":"Theres a big hole in the Feds theory of inflation—incomes are falling at a record 10.9 rate","author":"MarketWatch","published_utc":"2022-04-28T17:08:00Z","article_url":"https://www.marketwatch.com/story/theres-a-big-hole-in-the-feds-theory-of-inflationincomes-are-falling-at-a-record-10-9-rate-11651165705","tickers":["MSFT","TSN","NFLX","AMZN"],"amp_url":"https://www.marketwatch.com/amp/story/theres-a-big-hole-in-the-feds-theory-of-inflationincomes-are-falling-at-a-record-10-9-rate-11651165705","image_url":"https://images.mktw.net/im-533637/social","description":"If inflation is all due to an overly generous federal government giving its people too much money, then our inflation problem is about to go away."}],"status":"OK","request_id":"f5248459196e12f27520afd41cee5126","count":10}',
37+
),
38+
(
39+
"/v3/reference/tickers/types",
40+
'{"results":[{"code":"CS","description":"Common Stock","asset_class":"stocks","locale":"us"},{"code":"PFD","description":"Preferred Stock","asset_class":"stocks","locale":"us"},{"code":"WARRANT","description":"Warrant","asset_class":"stocks","locale":"us"},{"code":"RIGHT","description":"Rights","asset_class":"stocks","locale":"us"},{"code":"BOND","description":"Corporate Bond","asset_class":"stocks","locale":"us"},{"code":"ETF","description":"Exchange Traded Fund","asset_class":"stocks","locale":"us"},{"code":"ETN","description":"Exchange Traded Note","asset_class":"stocks","locale":"us"},{"code":"SP","description":"Structured Product","asset_class":"stocks","locale":"us"},{"code":"ADRC","description":"American Depository Receipt Common","asset_class":"stocks","locale":"us"},{"code":"ADRW","description":"American Depository Receipt Warrants","asset_class":"stocks","locale":"us"},{"code":"ADRR","description":"American Depository Receipt Rights","asset_class":"stocks","locale":"us"},{"code":"FUND","description":"Fund","asset_class":"stocks","locale":"us"},{"code":"BASKET","description":"Basket","asset_class":"stocks","locale":"us"},{"code":"UNIT","description":"Unit","asset_class":"stocks","locale":"us"},{"code":"LT","description":"Liquidating Trust","asset_class":"stocks","locale":"us"}],"status":"OK","request_id":"efbfc7c2304bba6c2f19a2567f568134","count":15}',
41+
),
2242
]
2343

2444

2545
class BaseTest(unittest.TestCase):
2646
@classmethod
2747
def setUpClass(cls):
48+
cls.maxDiff = None
2849
cls.c = RESTClient("")
2950
httpretty.enable(verbose=True, allow_net_connect=False)
3051
for m in mocks:

tests/test_tickers.py

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
from polygon import RESTClient
2+
from polygon.rest.models import (
3+
Ticker,
4+
TickerDetails,
5+
TickerNews,
6+
TickerTypes,
7+
)
8+
from mocks import BaseTest
9+
10+
11+
class TickersTest(BaseTest):
12+
def test_list_tickers(self):
13+
tickers = [t for t in self.c.list_tickers()]
14+
expected = [
15+
Ticker(
16+
active=True,
17+
cik=None,
18+
composite_figi="BBG00X5FSP48",
19+
currency_name="usd",
20+
currency_symbol=None,
21+
base_currency_symbol=None,
22+
base_currency_name=None,
23+
delisted_utc=None,
24+
last_updated_utc="2022-04-27T00:00:00Z",
25+
locale="us",
26+
market="stocks",
27+
name="AAF First Priority CLO Bond ETF",
28+
primary_exchange="ARCX",
29+
share_class_figi="BBG00X5FSPZ4",
30+
ticker="AAA",
31+
type="ETF",
32+
),
33+
Ticker(
34+
active=True,
35+
cik="0001708646",
36+
composite_figi="BBG00LPXX872",
37+
currency_name="usd",
38+
currency_symbol=None,
39+
base_currency_symbol=None,
40+
base_currency_name=None,
41+
delisted_utc=None,
42+
last_updated_utc="2022-04-27T00:00:00Z",
43+
locale="us",
44+
market="stocks",
45+
name="Goldman Sachs Physical Gold ETF Shares",
46+
primary_exchange="BATS",
47+
share_class_figi="BBG00LPXX8Z1",
48+
ticker="AAAU",
49+
type="ETF",
50+
),
51+
]
52+
self.assertEqual(tickers, expected)
53+
54+
def test_get_ticker_details(self):
55+
details = self.c.get_ticker_details("AAPL")
56+
expected = [
57+
TickerDetails(
58+
active=True,
59+
address={
60+
"address1": "ONE APPLE PARK WAY",
61+
"city": "CUPERTINO",
62+
"state": "CA",
63+
"postal_code": "95014",
64+
},
65+
branding={
66+
"logo_url": "https://api.polygon.io/v1/reference/company-branding/d3d3LmFwcGxlLmNvbQ/images/2022-02-01_logo.svg",
67+
"icon_url": "https://api.polygon.io/v1/reference/company-branding/d3d3LmFwcGxlLmNvbQ/images/2022-02-01_icon.png",
68+
},
69+
cik="0000320193",
70+
composite_figi="BBG000B9XRY4",
71+
currency_name="usd",
72+
delisted_utc=None,
73+
description="Apple designs a wide variety of consumer electronic devices, including smartphones (iPhone), tablets (iPad), PCs (Mac), smartwatches (Apple Watch), AirPods, and TV boxes (Apple TV), among others. The iPhone makes up the majority of Apples total revenue. In addition, Apple offers its customers a variety of services such as Apple Music, iCloud, Apple Care, Apple TV+, Apple Arcade, Apple Card, and Apple Pay, among others. Apples products run internally developed software and semiconductors, and the firm is well known for its integration of hardware, software and services. Apples products are distributed online as well as through company-owned stores and third-party retailers. The company generates roughly 40 of its revenue from the Americas, with the remainder earned internationally.",
74+
ticker_root="AAPL",
75+
homepage_url="https://www.apple.com",
76+
list_date="1980-12-12",
77+
locale="us",
78+
market="stocks",
79+
market_cap=2671492491700.0,
80+
name="Apple Inc.",
81+
phone_number="(408) 996-1010",
82+
primary_exchange="XNAS",
83+
share_class_figi="BBG001S5N8V8",
84+
share_class_shares_outstanding=16319440000,
85+
sic_code="3571",
86+
sic_description="ELECTRONIC COMPUTERS",
87+
ticker="AAPL",
88+
total_employees=154000,
89+
type="CS",
90+
weighted_shares_outstanding=16319441000,
91+
)
92+
]
93+
self.assertEqual(details, expected)
94+
95+
def test_list_ticker_news(self):
96+
news = [t for t in self.c.list_ticker_news("NFLX")]
97+
expected = [
98+
TickerNews(
99+
amp_url="https://www.marketwatch.com/amp/story/theres-a-big-hole-in-the-feds-theory-of-inflationincomes-are-falling-at-a-record-10-9-rate-11651165705",
100+
article_url="https://www.marketwatch.com/story/theres-a-big-hole-in-the-feds-theory-of-inflationincomes-are-falling-at-a-record-10-9-rate-11651165705",
101+
author="MarketWatch",
102+
description="If inflation is all due to an overly generous federal government giving its people too much money, then our inflation problem is about to go away.",
103+
id="JeJEhAVoKaqJ2zF9nzQYMg07UlEeWlis6Dsop33TPQY",
104+
image_url="https://images.mktw.net/im-533637/social",
105+
keywords=None,
106+
published_utc="2022-04-28T17:08:00Z",
107+
publisher={
108+
"name": "MarketWatch",
109+
"homepage_url": "https://www.marketwatch.com/",
110+
"logo_url": "https://s3.polygon.io/public/assets/news/logos/marketwatch.svg",
111+
"favicon_url": "https://s3.polygon.io/public/assets/news/favicons/marketwatch.ico",
112+
},
113+
tickers=["MSFT", "TSN", "NFLX", "AMZN"],
114+
title="Theres a big hole in the Feds theory of inflation—incomes are falling at a record 10.9 rate",
115+
)
116+
]
117+
self.assertEqual(news, expected)
118+
119+
def test_get_ticker_types(self):
120+
types = self.c.get_ticker_types("stocks")
121+
expected = [
122+
TickerTypes(
123+
asset_class="stocks", code="CS", description="Common Stock", locale="us"
124+
),
125+
TickerTypes(
126+
asset_class="stocks",
127+
code="PFD",
128+
description="Preferred Stock",
129+
locale="us",
130+
),
131+
TickerTypes(
132+
asset_class="stocks", code="WARRANT", description="Warrant", locale="us"
133+
),
134+
TickerTypes(
135+
asset_class="stocks", code="RIGHT", description="Rights", locale="us"
136+
),
137+
TickerTypes(
138+
asset_class="stocks",
139+
code="BOND",
140+
description="Corporate Bond",
141+
locale="us",
142+
),
143+
TickerTypes(
144+
asset_class="stocks",
145+
code="ETF",
146+
description="Exchange Traded Fund",
147+
locale="us",
148+
),
149+
TickerTypes(
150+
asset_class="stocks",
151+
code="ETN",
152+
description="Exchange Traded Note",
153+
locale="us",
154+
),
155+
TickerTypes(
156+
asset_class="stocks",
157+
code="SP",
158+
description="Structured Product",
159+
locale="us",
160+
),
161+
TickerTypes(
162+
asset_class="stocks",
163+
code="ADRC",
164+
description="American Depository Receipt Common",
165+
locale="us",
166+
),
167+
TickerTypes(
168+
asset_class="stocks",
169+
code="ADRW",
170+
description="American Depository Receipt Warrants",
171+
locale="us",
172+
),
173+
TickerTypes(
174+
asset_class="stocks",
175+
code="ADRR",
176+
description="American Depository Receipt Rights",
177+
locale="us",
178+
),
179+
TickerTypes(
180+
asset_class="stocks", code="FUND", description="Fund", locale="us"
181+
),
182+
TickerTypes(
183+
asset_class="stocks", code="BASKET", description="Basket", locale="us"
184+
),
185+
TickerTypes(
186+
asset_class="stocks", code="UNIT", description="Unit", locale="us"
187+
),
188+
TickerTypes(
189+
asset_class="stocks",
190+
code="LT",
191+
description="Liquidating Trust",
192+
locale="us",
193+
),
194+
]
195+
196+
self.assertEqual(types, expected)

0 commit comments

Comments
 (0)