Skip to content

Commit acbeaae

Browse files
committed
Added get_events and tests to client library.
RV1: - added get_events function to client library - added tests. RV2: - changed get_ticker_events to get_ticker_history RV3: - changed history to events and modifed classes to meet new requirements.
1 parent 24764cd commit acbeaae

File tree

4 files changed

+111
-0
lines changed

4 files changed

+111
-0
lines changed

polygon/rest/models/tickers.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import array
12
from typing import Optional, List
23

34
from ...modelclass import modelclass
@@ -185,3 +186,35 @@ class TickerTypes:
185186
@staticmethod
186187
def from_dict(d):
187188
return TickerTypes(**d)
189+
190+
191+
@modelclass
192+
class TickerChange:
193+
ticker: str
194+
195+
@staticmethod
196+
def from_dict(d):
197+
return TickerChange(**d)
198+
199+
200+
@modelclass
201+
class TickerChangeEvent:
202+
type: str
203+
date: str
204+
ticker_change: TickerChange
205+
206+
@staticmethod
207+
def from_dict(d):
208+
return TickerChangeEvent(**d)
209+
210+
211+
@modelclass
212+
class TickerChangeResults:
213+
name: str
214+
figi: str
215+
cik: str
216+
events: Optional[List[TickerChangeEvent]] = None
217+
218+
@staticmethod
219+
def from_dict(d):
220+
return TickerChangeResults(**d)

polygon/rest/reference.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
MarketHoliday,
55
MarketStatus,
66
Ticker,
7+
TickerChangeResults,
78
TickerDetails,
89
TickerNews,
910
TickerTypes,
@@ -143,6 +144,30 @@ def get_ticker_details(
143144
result_key="results",
144145
)
145146

147+
def get_ticker_events(
148+
self,
149+
ticker: Optional[str] = None,
150+
params: Optional[Dict[str, Any]] = None,
151+
raw: bool = False,
152+
) -> Union[TickerChangeResults, HTTPResponse]:
153+
154+
"""
155+
Get event history of ticker given particular point in time.
156+
:param ticker: The ticker symbol of the asset.
157+
:param params: Additional query parameters
158+
:param raw: Return raw object instead of results object.
159+
:return: Ticker Event VX
160+
"""
161+
url = f"/vX/reference/tickers/{ticker}/events"
162+
163+
return self._get(
164+
path=url,
165+
params=params,
166+
deserializer=TickerChangeResults.from_dict,
167+
result_key="results",
168+
raw=raw,
169+
)
170+
146171
def list_ticker_news(
147172
self,
148173
ticker: Optional[str] = None,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"results": {
3+
"name": "Meta Platforms, Inc. Class A Common Stock",
4+
"figi": "BBG000MM2P62",
5+
"cik": "0001326801",
6+
"events": [
7+
{
8+
"ticker_change": {
9+
"ticker": "META"
10+
},
11+
"type": "ticker_change",
12+
"date": "2022-06-11"
13+
},
14+
{
15+
"ticker_change": {
16+
"ticker": "FB"
17+
},
18+
"type": "ticker_change",
19+
"date": "2012-05-18"
20+
}
21+
]
22+
},
23+
"status": "OK",
24+
"request_id": "8c911ff1-5ca8-41e8-9bbf-e625141caacc"
25+
}

test_rest/test_tickers.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
TickerDetails,
44
TickerNews,
55
TickerTypes,
6+
TickerChangeEvent,
7+
TickerChangeResults,
68
Publisher,
79
Branding,
810
CompanyAddress,
@@ -230,3 +232,29 @@ def test_get_ticker_types(self):
230232
]
231233

232234
self.assertEqual(types, expected)
235+
236+
def test_get_ticker_events_ticker_change(self):
237+
events = self.c.get_ticker_events(ticker="META")
238+
expected = TickerChangeResults(
239+
name="Meta Platforms, Inc. Class A Common Stock",
240+
figi="BBG000MM2P62",
241+
cik="0001326801",
242+
events=[
243+
{
244+
"ticker_change": {
245+
"ticker": "META"
246+
},
247+
"type": "ticker_change",
248+
"date": "2022-06-11"
249+
},
250+
{
251+
"ticker_change": {
252+
"ticker": "FB"
253+
},
254+
"type": "ticker_change",
255+
"date": "2012-05-18"
256+
},
257+
]
258+
)
259+
260+
self.assertEqual(expected, events)

0 commit comments

Comments
 (0)