Skip to content

Commit 786a9d4

Browse files
author
Hitoshi Harada
committed
Add code snippet for polygon and sort DataFrame result
1 parent 7cc3c56 commit 786a9d4

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,15 @@ Alpaca's API key ID can be used to access Polygon API whose document is found [h
270270
This python SDK wraps their API service and seamlessly integrates with Alpaca API.
271271
`alpaca_trade_api.REST.polygon` will be the `REST` object for Polygon.
272272

273+
The example below gives AAPL daily OHLCV data in a DataFrame format.
274+
275+
```py
276+
import alpaca_trade_api as tradeapi
277+
278+
api = tradeapi.REST()
279+
aapl = api.polygon.historic_agg('day', 'AAPL', limit=1000).df
280+
```
281+
273282
## polygon/REST
274283
It is initialized through alpaca `REST` object.
275284

alpaca_trade_api/polygon/entity.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ def df(self):
7070
df.set_index('day', inplace=True)
7171
df.index = pd.to_datetime(
7272
df.index).tz_localize(NY)
73+
74+
df.sort_index(inplace=True)
7375
self._df = df
7476

7577
return self._df
@@ -119,7 +121,9 @@ def df(self):
119121
utc=True,
120122
).tz_convert(NY)
121123

124+
df.sort_index(inplace=True)
122125
self._df = df
126+
123127
return self._df
124128

125129

0 commit comments

Comments
 (0)