Skip to content

Commit 7796a50

Browse files
committed
Fix dataframe format for portfolio history
1 parent 5970c3c commit 7796a50

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

alpaca_trade_api/entity.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,18 @@ def __init__(self, raw):
165165
def df(self):
166166
if not hasattr(self, '_df'):
167167
df = pd.DataFrame(
168-
self._raw, columns=('time', 'profit_loss', 'profit_loss_pct', 'equity'),
168+
self._raw, columns=(
169+
'timestamp', 'profit_loss', 'profit_loss_pct', 'equity'
170+
),
169171
)
170-
df.set_index('time', inplace=True)
172+
df.set_index('timestamp', inplace=True)
171173
if not df.empty:
172174
df.index = pd.to_datetime(
173-
(df.index * 1e9).astype('int64'), utc=True,
175+
(df.index * 1e6).astype('int64'), utc=True,
174176
).tz_convert(NY)
175177
else:
176178
df.index = pd.to_datetime(
177179
df.index, utc=True
178180
)
179181
self._df = df
180-
return self._df
182+
return self._df

alpaca_trade_api/rest.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from .entity import (
1313
Account, AccountConfigurations, AccountActivity,
1414
Asset, Order, Position, BarSet, Clock, Calendar,
15-
Watchlist
15+
Watchlist, PortfolioHistory
1616
)
1717
from . import polygon
1818
from . import alpha_vantage
@@ -437,18 +437,20 @@ def delete_from_watchlist(self, watchlist_id, symbol):
437437
self.delete('/watchlists/{}/{}'.format(watchlist_id, symbol))
438438

439439
def get_portfolio_history(
440-
date_start=None, date_end=None, period=None,
440+
self, date_start=None, date_end=None, period=None,
441441
timeframe=None, extended_hours=None
442442
):
443443
params = {}
444444
if date_start is not None:
445445
params['date_start'] = date_start
446446
if date_end is not None:
447447
params['date_end'] = date_end
448-
if perioid is not None:
448+
if period is not None:
449449
params['period'] = period
450450
if timeframe is not None:
451451
params['timeframe'] = timeframe
452452
if extended_hours is not None:
453453
params['extended_hours'] = extended_hours
454-
return PortfolioHistory(self.get('account/portfolio/history', data=params))
454+
return PortfolioHistory(
455+
self.get('/account/portfolio/history', data=params)
456+
)

0 commit comments

Comments
 (0)