Skip to content

Commit a465ba5

Browse files
author
clickingbuttons
authored
fix get_ticker_details (#166)
* fix get_ticker_details * fix lint
1 parent 603d05b commit a465ba5

File tree

5 files changed

+59
-55
lines changed

5 files changed

+59
-55
lines changed

polygon/rest/models/tickers.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,8 @@ class TickerDetails:
9898
def from_dict(d):
9999
return TickerDetails(
100100
active=d.get("active", None),
101-
address=None if "address" not in d else [Address.from_dict(d["address"])],
102-
branding=None
103-
if "branding" not in d
104-
else [Branding.from_dict(d["branding"])],
101+
address=None if "address" not in d else Address.from_dict(d["address"]),
102+
branding=None if "branding" not in d else Branding.from_dict(d["branding"]),
105103
cik=d.get("cik", None),
106104
composite_figi=d.get("composite_figi", None),
107105
currency_name=d.get("currency_name", None),

polygon/rest/reference.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,11 @@ def get_ticker_details(
135135
url = f"/v3/reference/tickers/{ticker}"
136136

137137
return self._get(
138-
path=url, params=params, deserializer=TickerDetails.from_dict, raw=raw
138+
path=url,
139+
params=params,
140+
deserializer=TickerDetails.from_dict,
141+
raw=raw,
142+
result_key="results",
139143
)
140144

141145
def list_ticker_news(

rest-example.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
print(aggs)
88
aggs = client.get_aggs("AAPL", 1, "day", date(2005, 4, 4), datetime(2005, 4, 4))
99
print(aggs)
10+
details = client.get_ticker_details('AAPL')
11+
print(details)
Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
11
{
2-
"ticker": "AAPL",
3-
"name": "Apple Inc.",
4-
"market": "stocks",
5-
"locale": "us",
6-
"primary_exchange": "XNAS",
7-
"type": "CS",
8-
"active": true,
9-
"currency_name": "usd",
10-
"cik": "0000320193",
11-
"composite_figi": "BBG000B9XRY4",
12-
"share_class_figi": "BBG001S5N8V8",
13-
"market_cap": 2671492491700.0,
14-
"phone_number": "(408) 996-1010",
15-
"address": {
16-
"address1": "ONE APPLE PARK WAY",
17-
"city": "CUPERTINO",
18-
"state": "CA",
19-
"postal_code": "95014"
20-
},
21-
"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.",
22-
"sic_code": "3571",
23-
"sic_description": "ELECTRONIC COMPUTERS",
24-
"ticker_root": "AAPL",
25-
"homepage_url": "https://www.apple.com",
26-
"total_employees": 154000,
27-
"list_date": "1980-12-12",
28-
"branding": {
29-
"logo_url": "https://api.polygon.io/v1/reference/company-branding/d3d3LmFwcGxlLmNvbQ/images/2022-02-01_logo.svg",
30-
"icon_url": "https://api.polygon.io/v1/reference/company-branding/d3d3LmFwcGxlLmNvbQ/images/2022-02-01_icon.png"
31-
},
32-
"share_class_shares_outstanding": 16319440000,
33-
"weighted_shares_outstanding": 16319441000
34-
}
2+
"results": {
3+
"ticker": "AAPL",
4+
"name": "Apple Inc.",
5+
"market": "stocks",
6+
"locale": "us",
7+
"primary_exchange": "XNAS",
8+
"type": "CS",
9+
"active": true,
10+
"currency_name": "usd",
11+
"cik": "0000320193",
12+
"composite_figi": "BBG000B9XRY4",
13+
"share_class_figi": "BBG001S5N8V8",
14+
"market_cap": 2488795282370,
15+
"phone_number": "(408) 996-1010",
16+
"address": {
17+
"address1": "ONE APPLE PARK WAY",
18+
"city": "CUPERTINO",
19+
"state": "CA",
20+
"postal_code": "95014"
21+
},
22+
"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 Apple's 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. Apple's products run internally developed software and semiconductors, and the firm is well known for its integration of hardware, software and services. Apple's 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.",
23+
"sic_code": "3571",
24+
"sic_description": "ELECTRONIC COMPUTERS",
25+
"ticker_root": "AAPL",
26+
"homepage_url": "https://www.apple.com",
27+
"total_employees": 154000,
28+
"list_date": "1980-12-12",
29+
"branding": {
30+
"logo_url": "https://api.polygon.io/v1/reference/company-branding/d3d3LmFwcGxlLmNvbQ/images/2022-05-01_logo.svg",
31+
"icon_url": "https://api.polygon.io/v1/reference/company-branding/d3d3LmFwcGxlLmNvbQ/images/2022-05-01_icon.png"
32+
},
33+
"share_class_shares_outstanding": 16319440000,
34+
"weighted_shares_outstanding": 16185181000
35+
},
36+
"status": "OK",
37+
"request_id": "ce8688b5f3a571351376ebd77acd146e"
38+
}

test_rest/test_tickers.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,31 +93,27 @@ def test_get_ticker_details(self):
9393
details = self.c.get_ticker_details("AAPL")
9494
expected = TickerDetails(
9595
active=True,
96-
address=[
97-
Address(
98-
address1="ONE APPLE PARK WAY",
99-
city="CUPERTINO",
100-
state="CA",
101-
postal_code="95014",
102-
)
103-
],
104-
branding=[
105-
Branding(
106-
icon_url="https://api.polygon.io/v1/reference/company-branding/d3d3LmFwcGxlLmNvbQ/images/2022-02-01_icon.png",
107-
logo_url="https://api.polygon.io/v1/reference/company-branding/d3d3LmFwcGxlLmNvbQ/images/2022-02-01_logo.svg",
108-
)
109-
],
96+
address=Address(
97+
address1="ONE APPLE PARK WAY",
98+
city="CUPERTINO",
99+
state="CA",
100+
postal_code="95014",
101+
),
102+
branding=Branding(
103+
icon_url="https://api.polygon.io/v1/reference/company-branding/d3d3LmFwcGxlLmNvbQ/images/2022-05-01_icon.png",
104+
logo_url="https://api.polygon.io/v1/reference/company-branding/d3d3LmFwcGxlLmNvbQ/images/2022-05-01_logo.svg",
105+
),
110106
cik="0000320193",
111107
composite_figi="BBG000B9XRY4",
112108
currency_name="usd",
113109
delisted_utc=None,
114-
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.",
110+
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 Apple's 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. Apple's products run internally developed software and semiconductors, and the firm is well known for its integration of hardware, software and services. Apple's 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.",
115111
ticker_root="AAPL",
116112
homepage_url="https://www.apple.com",
117113
list_date="1980-12-12",
118114
locale="us",
119115
market="stocks",
120-
market_cap=2671492491700.0,
116+
market_cap=2488795282370,
121117
name="Apple Inc.",
122118
phone_number="(408) 996-1010",
123119
primary_exchange="XNAS",
@@ -128,7 +124,7 @@ def test_get_ticker_details(self):
128124
ticker="AAPL",
129125
total_employees=154000,
130126
type="CS",
131-
weighted_shares_outstanding=16319441000,
127+
weighted_shares_outstanding=16185181000,
132128
)
133129
self.assertEqual(details, expected)
134130

0 commit comments

Comments
 (0)