Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion polygon/rest/models/tickers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class Ticker:
cik: Optional[str] = None
composite_figi: Optional[str] = None
currency_name: Optional[str] = None
currency_symbol: Optional[str] = None
base_currency_symbol: Optional[str] = None
base_currency_name: Optional[str] = None
delisted_utc: Optional[str] = None
last_updated_utc: Optional[str] = None
locale: Optional[Locale] = None
Expand All @@ -57,6 +60,7 @@ class TickerDetails:
currency_name: Optional[str] = None
delisted_utc: Optional[str] = None
description: Optional[str] = None
ticker_root: Optional[str] = None
homepage_url: Optional[str] = None
list_date: Optional[str] = None
locale: Optional[Locale] = None
Expand Down Expand Up @@ -109,4 +113,4 @@ class TickerTypes:

@staticmethod
def from_dict(d):
return TickerNews(**d)
return TickerTypes(**d)
8 changes: 6 additions & 2 deletions polygon/rest/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def get_ticker_types(
locale: Optional[Union[str, Locale]] = None,
params: Optional[Dict[str, Any]] = None,
raw: bool = False,
) -> Union[TickerTypes, HTTPResponse]:
) -> Union[List[TickerTypes], HTTPResponse]:
"""
List all ticker types that Polygon.io has.

Expand All @@ -188,7 +188,11 @@ def get_ticker_types(
url = "/v3/reference/tickers/types"

return self._get(
path=url, params=params, deserializer=TickerTypes.from_dict, raw=raw
path=url,
params=params,
deserializer=TickerTypes.from_dict,
raw=raw,
result_key="results",
)


Expand Down
21 changes: 21 additions & 0 deletions tests/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,33 @@
"/v2/aggs/ticker/AAPL/prev",
'{"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}',
),
(
"/v3/reference/tickers",
'{"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"}',
),
(
"/v3/reference/tickers?cursor=YWN0aXZlPXRydWUmZGF0ZT0yMDIyLTA0LTI3JmxpbWl0PTImb3JkZXI9YXNjJnBhZ2VfbWFya2VyPUFBJTdDZjEyMmJjYmY4YWQwNzRmZmJlMTZmNjkxOWQ0ZDc3NjZlMzA3MWNmNmU1Nzg3OGE0OGU1NjQ1YzQyM2U3NzJhOSZzb3J0PXRpY2tlcg",
'{"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}',
),
(
"/v3/reference/tickers/AAPL",
'{"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}',
),
(
"/v2/reference/news",
'{"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}',
),
(
"/v3/reference/tickers/types",
'{"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}',
),
]


class BaseTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.maxDiff = None
cls.c = RESTClient("")
httpretty.enable(verbose=True, allow_net_connect=False)
for m in mocks:
Expand Down
196 changes: 196 additions & 0 deletions tests/test_tickers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
from polygon import RESTClient
from polygon.rest.models import (
Ticker,
TickerDetails,
TickerNews,
TickerTypes,
)
from mocks import BaseTest


class TickersTest(BaseTest):
def test_list_tickers(self):
tickers = [t for t in self.c.list_tickers()]
expected = [
Ticker(
active=True,
cik=None,
composite_figi="BBG00X5FSP48",
currency_name="usd",
currency_symbol=None,
base_currency_symbol=None,
base_currency_name=None,
delisted_utc=None,
last_updated_utc="2022-04-27T00:00:00Z",
locale="us",
market="stocks",
name="AAF First Priority CLO Bond ETF",
primary_exchange="ARCX",
share_class_figi="BBG00X5FSPZ4",
ticker="AAA",
type="ETF",
),
Ticker(
active=True,
cik="0001708646",
composite_figi="BBG00LPXX872",
currency_name="usd",
currency_symbol=None,
base_currency_symbol=None,
base_currency_name=None,
delisted_utc=None,
last_updated_utc="2022-04-27T00:00:00Z",
locale="us",
market="stocks",
name="Goldman Sachs Physical Gold ETF Shares",
primary_exchange="BATS",
share_class_figi="BBG00LPXX8Z1",
ticker="AAAU",
type="ETF",
),
]
self.assertEqual(tickers, expected)

def test_get_ticker_details(self):
details = self.c.get_ticker_details("AAPL")
expected = [
TickerDetails(
active=True,
address={
"address1": "ONE APPLE PARK WAY",
"city": "CUPERTINO",
"state": "CA",
"postal_code": "95014",
},
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",
},
cik="0000320193",
composite_figi="BBG000B9XRY4",
currency_name="usd",
delisted_utc=None,
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.",
ticker_root="AAPL",
homepage_url="https://www.apple.com",
list_date="1980-12-12",
locale="us",
market="stocks",
market_cap=2671492491700.0,
name="Apple Inc.",
phone_number="(408) 996-1010",
primary_exchange="XNAS",
share_class_figi="BBG001S5N8V8",
share_class_shares_outstanding=16319440000,
sic_code="3571",
sic_description="ELECTRONIC COMPUTERS",
ticker="AAPL",
total_employees=154000,
type="CS",
weighted_shares_outstanding=16319441000,
)
]
self.assertEqual(details, expected)

def test_list_ticker_news(self):
news = [t for t in self.c.list_ticker_news("NFLX")]
expected = [
TickerNews(
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",
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",
author="MarketWatch",
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.",
id="JeJEhAVoKaqJ2zF9nzQYMg07UlEeWlis6Dsop33TPQY",
image_url="https://images.mktw.net/im-533637/social",
keywords=None,
published_utc="2022-04-28T17:08:00Z",
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",
},
tickers=["MSFT", "TSN", "NFLX", "AMZN"],
title="Theres a big hole in the Feds theory of inflation—incomes are falling at a record 10.9 rate",
)
]
self.assertEqual(news, expected)

def test_get_ticker_types(self):
types = self.c.get_ticker_types("stocks")
expected = [
TickerTypes(
asset_class="stocks", code="CS", description="Common Stock", locale="us"
),
TickerTypes(
asset_class="stocks",
code="PFD",
description="Preferred Stock",
locale="us",
),
TickerTypes(
asset_class="stocks", code="WARRANT", description="Warrant", locale="us"
),
TickerTypes(
asset_class="stocks", code="RIGHT", description="Rights", locale="us"
),
TickerTypes(
asset_class="stocks",
code="BOND",
description="Corporate Bond",
locale="us",
),
TickerTypes(
asset_class="stocks",
code="ETF",
description="Exchange Traded Fund",
locale="us",
),
TickerTypes(
asset_class="stocks",
code="ETN",
description="Exchange Traded Note",
locale="us",
),
TickerTypes(
asset_class="stocks",
code="SP",
description="Structured Product",
locale="us",
),
TickerTypes(
asset_class="stocks",
code="ADRC",
description="American Depository Receipt Common",
locale="us",
),
TickerTypes(
asset_class="stocks",
code="ADRW",
description="American Depository Receipt Warrants",
locale="us",
),
TickerTypes(
asset_class="stocks",
code="ADRR",
description="American Depository Receipt Rights",
locale="us",
),
TickerTypes(
asset_class="stocks", code="FUND", description="Fund", locale="us"
),
TickerTypes(
asset_class="stocks", code="BASKET", description="Basket", locale="us"
),
TickerTypes(
asset_class="stocks", code="UNIT", description="Unit", locale="us"
),
TickerTypes(
asset_class="stocks",
code="LT",
description="Liquidating Trust",
locale="us",
),
]

self.assertEqual(types, expected)