Skip to content

Commit 200f667

Browse files
committed
1 parent cd22b33 commit 200f667

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

alpaca_trade_api/polygon/rest.py

+32
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime
2+
from enum import Enum
23
from typing import List
34
import dateutil.parser
45
import requests
@@ -15,6 +16,24 @@
1516
Symbols = List[Symbol]
1617

1718

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+
1837
def _is_list_like(o) -> bool:
1938
"""
2039
returns True if o is either a list, a set or a tuple
@@ -273,6 +292,19 @@ def earnings(self, symbol: str) -> Earnings:
273292
def financials(self, symbol: str) -> Financials:
274293
return self._get_symbol(symbol, 'financials', Financials)
275294

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+
276308
def news(self, symbol: str) -> NewsList:
277309
path = '/meta/symbols/{}/news'.format(symbol)
278310
return NewsList(self.get(path))

0 commit comments

Comments
 (0)