Here is my understanding of the situation -- please correct me where I am in error:
- The PartFilled Quantity is the quantity of that partial fill only, not the accumulated quantity of all partial fills to date
- The Filled Quantity is either:
- The full quantity of the original submitted order if there are no partial fills, or
- The remainder of the submitted quantity after all partial fill quantities have been accumulated
- To determine when a submitted order has been completely filled, the fill update and any partial fill updates must all be used
- To accurately calculate the quantity when there is one or more partial fills, sum the quantities of every partial fill and the final fill
- To accurately calculate the average fill price when there is one or more partial fills, pro rata the average fill price of each fill to obtain a final average fill price
- The way partial fills and fills work is identical for all order types (i.e. the same for Enter and Exit orders for Market, Limit, Stop and StopLimit, as well as Trailing Stop and Profit Target)
- When handling partial fills and fills in OnOrderUpdate, sometimes a fill update may arrive before a partial fill update -- one must compare the submitted quantity against the fill update quantity to determine if partial fill updates may follow.
Here are some examples of calculating quantities and average fill price:
- Fill only (no partial fills)
- Enter Quantity = 100
- Fill, Quantity = 100 @ 1.12 avg fill price
- PartFill + Fill
- Enter Quantity = 100
- Partial fill, Quantity = 20 @ 1.00 avg fill price
- Fill Quantity = 80 @ 1.20 avg fill price
- Total Quantity = 20 + 80 = 100
- Average fill price = ((20 x 1.00) + (80 x 1.20)) / 100 = 1.16
- PartFills + Fill
- Enter Quantity = 100
- First partial fill, Quantity = 20 @ 1.00 avg fill price
- Second partial fill, Quantity = 20 @ 1.10 avg fill price
- Fill Quantity = 60 @ 1.20 avg fill price
- Total Quantity = 20 + 20 + 60 = 100
- Average fill price = ((20 x 1.00) + (20 x 1.10) + (60 x 1.20)) / 100 = 1.14
Many thanks for advice to correct any misunderstandings I may have.
Comment