|
| 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