Skip to content

Commit

Permalink
Handle null last trade data from Polygon with NaN & NaT when querying…
Browse files Browse the repository at this point in the history
… portfolio
  • Loading branch information
ttt733 committed Nov 29, 2018
1 parent 3907021 commit 99b519f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pylivetrader/backend/alpaca.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,13 @@ def positions(self):

trades = self._symbol_trades(symbols)
for symbol, trade in trades.items():
price = trade.price
dt = trade.timestamp
z_position = position_map[symbol]
z_position.last_sale_price = float(price)
z_position.last_sale_date = dt
if trade is None:
z_position.last_sale_price = np.nan
z_position.last_sale_date = pd.NaT
else:
z_position.last_sale_price = float(trade.price)
z_position.last_sale_date = trade.timestamp
return z_positions

@property
Expand Down

0 comments on commit 99b519f

Please sign in to comment.