Sub topic 11
Canceling and modifying an open order
Submitting an order is not the end of the process. A limit order can sit on the book for hours, and during that time you may change your mind, see the price move away, or notice a typo. This chapter covers how to cancel or change an order that is still working, and what can go wrong when you do.
This chapter assumes you know how limit orders and time in force work, and that you can read the order statuses covered in the previous chapter: open, partially filled, filled and canceled. This is educational material, not investment advice.
Which orders can you change?
Only an order that is still working can be canceled or modified. A working order has been accepted by the broker and sent to a market, and it has shares left to fill. Orders in a final state, such as filled, canceled or rejected, cannot be touched.
| Status | Can you cancel? | Can you modify? |
|---|---|---|
| Open (working, no fills yet) | Yes | Yes |
| Partially filled | Yes, but only the unfilled part | Usually yes, with limits on quantity |
| Filled | No | No |
| Canceled or rejected | No | No |
| Pending cancel or pending replace | Wait for the result | Wait for the result |
Market orders during regular hours usually fill within a moment, so you rarely get a chance to cancel one. Limit orders, and later stop orders, are the ones you will manage in practice.
Canceling is a request, not a command
When you press Cancel, your broker sends a cancel request to the venue where the order is resting. The venue then answers in one of two ways:
- It confirms the cancel, and the order becomes canceled.
- It rejects the cancel because the order filled first.
This race is the main thing to understand. Between your click and the venue's reply, another trader can trade against your order. If that happens, the fill stands and you own the shares. Brokers often show a transitional status such as "pending cancel" until the venue answers. Do not treat an order as gone while it shows that status.
Canceling after a partial fill
If your order was for 100 shares and 40 have traded, canceling removes only the remaining 60. The 40 shares stay in your account. After the cancel you hold a real 40-share position, and you should decide whether that size is acceptable on its own. Many brokers label this outcome "canceled" with a filled quantity of 40. Check the filled quantity, not just the status word.
What "modify" really does
Most retail platforms offer an Edit or Replace button. Behind it, the exchange usually treats a change as a cancel of the old order followed by a new order with your updated terms. Several consequences follow:
- The modified order may get a new order ID. If you track orders by ID, the old one will show as replaced or canceled.
- The new order goes to the back of the line at its price. Orders at the same price usually fill in the order they arrived, so you lose your place in the queue.
- A reduction in quantity sometimes keeps queue priority, but this depends on the venue and the broker. Do not count on it.
- The same race exists. If the old order fills while the replace is pending, the replace may be rejected, or it may apply only to what remains.
Typical fields you can change are the quantity, the limit price and the time in force. You usually cannot change the side (buy to sell) or the symbol. For those, cancel and enter a new order.
Modifying into a marketable price
Suppose you have a resting buy limit at 49.90 and the ask is 50.02. If you edit the limit to 50.10, the order is now marketable. A marketable limit order is one whose price already crosses the opposite side of the quote. It fills right away against the asks, up to your limit. This is a legitimate way to get filled, and the limit still caps your price at 50.10. But you have changed the order from patient to impatient, and you will pay the spread. Make this change on purpose, not by accident.
Modeling cancel and replace
The short program below models the rules above. It tracks fills, cancels only the unfilled part, and rejects a cancel on a filled order. Replacing creates a new order for the remaining shares.
from dataclasses import dataclass
@dataclass
class Order:
order_id: int
side: str
qty: int
limit: float
filled: int = 0
status: str = "open"
@property
def remaining(self):
return self.qty - self.filled
def is_working(self):
return self.status in ("open", "partially filled")
def fill(self, shares):
if not self.is_working():
raise ValueError("order is not working")
self.filled += min(shares, self.remaining)
self.status = "filled" if self.remaining == 0 else "partially filled"
def cancel(self):
if not self.is_working():
return f"rejected: order is already {self.status}"
self.status = "canceled"
return f"canceled with {self.filled} of {self.qty} filled"
def replace(order, new_limit, new_id):
"""Cancel the old order and return a new one for the unfilled shares."""
if not order.is_working():
raise ValueError(f"cannot replace an order that is {order.status}")
order.status = "canceled"
return Order(new_id, order.side, order.remaining, new_limit)
first = Order(1, "buy", 100, 49.90)
first.fill(40)
print(first.status, first.filled) # partially filled 40
second = replace(first, 50.00, 2)
print(first.status) # canceled
print(second) # 60 shares left, limit 50.0, status open
second.fill(60)
print(second.cancel()) # rejected: order is already filledThe last line shows the race. The cancel arrives after the order filled, so it is rejected and you keep the shares. Also notice that the replacement order covers 60 shares, not 100. Re-entering the original 100 would double the position you intended.
Buying power and open orders
An open buy order reserves buying power, which is the cash your broker lets you spend. If you place a buy of 20 shares at a limit of 50.00, your broker may hold about 1,000 of your funds while the order works. That money is not available for other trades. It is released when the cancel is confirmed, not when you click. If you cancel one order to fund another, wait until the first shows as canceled.
Common errors
- Cancel and re-enter without checking fills. If the original order partially filled in the meantime, a new full-size order gives you more shares than you planned. Always read the filled quantity first.
- Placing a second order before the first is gone. If the cancel is still pending and the original fills, both orders can end up executed.
- Chasing the price. Raising a buy limit a few cents at a time after each move makes you pay more, and each edit sends you to the back of the queue. If you decided the trade is worth taking, choose a limit based on your plan, not on the last tick.
- Forgetting good-til-canceled (GTC) orders. A GTC order stays active across days, usually up to a broker-set limit such as 60 or 90 days. If your view changed, cancel it. A stale order can fill days later at a price you no longer want.
- Assuming the screen is current. Platforms can lag. Refresh the order list and confirm the final status before acting again.
- Trying to cancel a market order. In liquid stocks it has usually filled before you can act. Do not rely on canceling as a safety net. Use a limit order if you want control.
A short routine for managing a working order
- Open the order list and find the order by symbol, side and quantity.
- Read its status and filled quantity.
- Decide whether you want to cancel, modify, or leave it. If you want a different price, ask whether the new price matches your plan or only the latest tick.
- Send the request and wait for a confirmed final status.
- Recheck your position and your available buying power.
- If you still want exposure, place a new order sized to the remaining shares you want, not to the original size.
Exercise
You placed a buy limit for 100 shares at 49.90. The platform shows 40 shares filled and 60 open. You edit the limit to 50.00, and the broker implements the edit as cancel and replace. How many shares does the replacement order cover, what happens to your queue position at the new price, and what should you check if the replace comes back rejected?
Show answer
The replacement covers the 60 unfilled shares, so you still end at 100 shares if it fills completely. The new order goes to the back of the queue at its price, so you lose any time priority the old order had. A rejected replace usually means the order filled or changed state before the request arrived. Check the filled quantity and status: if all 100 shares filled, you already own the full position and should not enter another order.