|
1 | 1 | import datetime
|
| 2 | +from enum import Enum |
2 | 3 | from typing import List
|
3 | 4 | import dateutil.parser
|
4 | 5 | import requests
|
|
15 | 16 | Symbols = List[Symbol]
|
16 | 17 |
|
17 | 18 |
|
| 19 | +class FinancialsReportType(Enum): |
| 20 | + "https://polygon.io/docs/get_v2_reference_financials__stocksTicker__anchor" |
| 21 | + Y = "Year" |
| 22 | + YA = "Year annualized" |
| 23 | + Q = "Quarter" |
| 24 | + QA = "Quarter Annualized" |
| 25 | + T = "Trailing twelve months" |
| 26 | + TA = "trailing twelve months annualized" |
| 27 | + |
| 28 | + |
| 29 | +class FinancialsSort(Enum): |
| 30 | + "https://polygon.io/docs/get_v2_reference_financials__stocksTicker__anchor" |
| 31 | + ReportPeriodAsc = "reportPeriod" |
| 32 | + ReportPeriodDesc = "-reportPeriod" |
| 33 | + CalendarDateAsc = "calendarDate" |
| 34 | + CalendarDateDesc = "-calendarDate" |
| 35 | + |
| 36 | + |
18 | 37 | def _is_list_like(o) -> bool:
|
19 | 38 | """
|
20 | 39 | returns True if o is either a list, a set or a tuple
|
@@ -273,6 +292,19 @@ def earnings(self, symbol: str) -> Earnings:
|
273 | 292 | def financials(self, symbol: str) -> Financials:
|
274 | 293 | return self._get_symbol(symbol, 'financials', Financials)
|
275 | 294 |
|
| 295 | + def financials_v2(self, symbol: str, |
| 296 | + limit: int, |
| 297 | + report_type: FinancialsReportType, |
| 298 | + sort: FinancialsSort |
| 299 | + ) -> Financials: |
| 300 | + path = f'/reference/financials/{symbol}' |
| 301 | + params = {"limit": limit, |
| 302 | + "type": report_type.name, |
| 303 | + "sort": sort.value, |
| 304 | + } |
| 305 | + return Financials(self.get(path, version='v2', |
| 306 | + params=params)['results']) |
| 307 | + |
276 | 308 | def news(self, symbol: str) -> NewsList:
|
277 | 309 | path = '/meta/symbols/{}/news'.format(symbol)
|
278 | 310 | return NewsList(self.get(path))
|
|
0 commit comments