last_sale_price is a part of portfolio object. One would think that would be the price at which the last trade for that security was placed. Similar to cost basis, but not averaged over past trades. For example if one bought IBM for 77 then for 79, the last sale price should be 79 regardless of the current price of the security.
As it turns out, the behavior of the object is as follows, at least according to my test:
- Before any trade is executed last price is zero
- After an order is placed, last price is still zero, presumably the order is not executed yet
- After the order is executed, last price becomes equal to current trading price of the security.
That is, once we trade it, the last_sale_price of a security in portfolio becomes equal at any point to the security price. This in non-intuitive at best as one can simply get the price from data[].price. I believe the intent of the field was to record and keep the last price at which the security was traded in one's portfolio, not to duplicate the behavior of otherwise available current price of the security. If that indeed was the intention than this is a bug in last_sale_price method implementation.