Skip to content

Commit

Permalink
Merge pull request #57 from alpacahq/handleNullLastTrades
Browse files Browse the repository at this point in the history
Handle null last trade data from Polygon with NaN & NaT when querying…
  • Loading branch information
ttt733 authored Nov 29, 2018
2 parents 1491a2d + 99b519f commit 4efc5bb
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 4efc5bb

Please sign in to comment.