You send a limit order and half of it fills. On screen the position shows as open, and the bot knows it is open too. What it does not know is that the position is smaller than planned, and that the stop order is still sized against the full quantity.
Why partial fills happen
When the quantity resting on the other side at your limit price is smaller than your order, only that much fills and the remainder keeps waiting in the book. This is normal operation.
The second cause is time. Part of the order fills, the price moves away, and the remainder never fills at all. Cancel it and you are left holding half a position.
The third is large orders. A quantity above the depth of the book cannot fill in one go by definition.
Three records that break
Average cost. An order filled at two different prices does not have one price. It needs a quantity-weighted average, and taking a plain average gives the wrong answer unless the two pieces happen to be the same size.
Stop size. A stop order should match the open position. A stop sent for the full quantity can, against a half position, open a short in the opposite direction; depending on the exchange it is either rejected or quietly accepted.
The risk calculation. If you sized the position against a risk percentage, an order that half fills has taken on half the risk. That sounds like good news, and it also halves the strategy’s expected return.
The one check on the bot side
After sending an order, the bot has to compare two numbers: the quantity sent and the quantity filled.
If they match, the flow continues. If they do not, there are three options and which one applies depends on the strategy: cancel the rest and manage the position at the filled size, complete the rest with a market order, or wait a while longer.
Whichever is chosen, every calculation after it has to run on the filled quantity. That one-line rule removes most of the errors partial fills produce.
The difference on commission
An order filling in three pieces does not count as one trade on most exchanges: three separate fill records are produced and commission is charged against each of them. Three records, three charges.
On exchanges applying a fixed minimum commission the gap widens: an order that fills in small pieces costs more than a single-piece order of the same size. The cost report has to be read per fill record rather than per order.
A backtest cannot produce this
Most backtest engines either fill an order completely or not at all. In a real book there is a region in between, and that region determines the strategy’s actual position size.
Simulating it properly wants order book data. That is heavy for most setups. An approximate correction does the job: if your order size crosses the fraction of average traded volume you picked, treat the order as partially filled in the test.



