Skip to content

Commit 10e56fc

Browse files
authored
Merge pull request #55 from alpacahq/ticker-endpoint
Add support for Polygon ticker snapshots
2 parents 88fbb67 + 8b8f9e8 commit 10e56fc

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

alpaca_trade_api/polygon/entity.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,7 @@ class News(Entity):
209209

210210
class NewsList(EntityList):
211211
_entity_class = News
212+
213+
214+
class Ticker(Entity):
215+
pass

alpaca_trade_api/polygon/rest.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Trade, Trades,
55
Quote, Quotes,
66
Exchange, SymbolTypeMap, ConditionMap,
7-
Company, Dividends, Splits, Earnings, Financials, NewsList
7+
Company, Dividends, Splits, Earnings, Financials, NewsList, Ticker
88
)
99

1010

@@ -19,8 +19,8 @@ def __init__(self, api_key, staging=False):
1919
self._staging = staging
2020
self._session = requests.Session()
2121

22-
def _request(self, method, path, params=None):
23-
url = 'https://api.polygon.io/v1' + path
22+
def _request(self, method, path, params=None, version='v1'):
23+
url = 'https://api.polygon.io/' + version + path
2424
params = params or {}
2525
params['apiKey'] = self._api_key
2626
if self._staging:
@@ -29,8 +29,8 @@ def _request(self, method, path, params=None):
2929
resp.raise_for_status()
3030
return resp.json()
3131

32-
def get(self, path, params=None):
33-
return self._request('GET', path, params=params)
32+
def get(self, path, params=None, version='v1'):
33+
return self._request('GET', path, params=params, version=version)
3434

3535
def exchanges(self):
3636
path = '/meta/exchanges'
@@ -127,3 +127,14 @@ def financials(self, symbol):
127127
def news(self, symbol):
128128
path = '/meta/symbols/{}/news'.format(symbol)
129129
return NewsList(self.get(path))
130+
131+
def all_tickers(self):
132+
path = '/snapshot/locale/us/markets/stocks/tickers'
133+
return [
134+
Ticker(ticker) for ticker in
135+
self.get(path, version='v2')['tickers']
136+
]
137+
138+
def snapshot(self, symbol):
139+
path = '/snapshot/locale/us/markets/stocks/tickers/{}'.format(symbol)
140+
return Ticker(self.get(path, version='v2'))

0 commit comments

Comments
 (0)