Question
Hello all, I’m currently using the Alpaca v2 streaming API to listen to updates on my trades. I’m looking for the correct way to know how many shares were filled in the latest partial fill update I receive, and the average price for that set.
Example
Let’s say I own 40 shares of AAPL. I put out a limit buy for 100 shares of AAPL at $316.20. This order fills in 3 bursts:
- 20 shares at average $315.89
- 50 shares at average $316.07
- 30 shares at average $316.00
Listening to the streaming API, I believe I would see:
{
event: partial_fill,
price: 315.89,
position_qty: 60,
order: {
qty: 100,
filled_qty: 20,
filled_avg_price: 315.89
}
}
{
event: partial_fill,
price: A,
position_qty: 110,
order: {
qty: 100,
filled_qty: 70,
filled_avg_price: 316.02
}
}
{
event: partial_fill,
price: B,
position_qty: 140,
order: {
qty: 100,
filled_qty: 100,
filled_avg_price: 316.01
}
}
(Irrelevant fields are omitted).
I used A and B as placeholders above because I’m not sure what those values would be in this case. The filled_avg_price
is the average price for the total number of filled shares, not the average price for the shares filled in that update.
The numbers that I want are the ones I provided in the beginning (20/315.89, 50/316.07, and 30/316.00). Is there a way to get those numbers via the streaming API? (Obviously I could derive them myself doing some simple math, if my app remembers the previous values and never drops a connection, but I’d prefer not to do that.) Thanks!