Getting quantities on partial fills

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:

  1. 20 shares at average $315.89
  2. 50 shares at average $316.07
  3. 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!

Hey, sorry I missed this. The streaming is giving the updated order information which records only filled qty so far, but I can see it could be useful to know how many shares are filled for this update.

The workaround right now is to use Account Activities API to get the FILL items which should have the particular fill information, but we consider adding more information for the streaming too.

@garrettd as mentioned on your GitHub issue, the (partial) fill trade update message now includes a qty field which equals to the quantity of shares filled in that update along with price which equals to the price it was filled at. Thanks for the feedback!

1 Like