DEV Community

Milton Altenwerth
Milton Altenwerth

Posted on

What Happens When You Cancel a Partially Filled Limit Order?

Canceling a partially filled limit order stops its remaining quantity only when the cancellation takes effect under that order system’s rules; any fill that wins the race may still settle. The filled portion stays filled, while the fate and availability of the remainder depend on whether the order is held onchain, by a service, or represented by a signed authorization.

What exactly does cancellation remove?

Cancellation targets the unfilled remainder, not the trade already executed. If an order was for 10 tokens and 4 have filled, a successful cancellation should leave the 4-token trade intact and prevent the other 6 from filling afterward.

The important distinction is between an interface showing “cancel requested” and the order becoming unfillable. Some systems remove an order from an offchain order book when they receive a cancellation request; others require an onchain transaction or an onchain nonce change. Until the relevant state change is recognized, a filler may still submit a valid fill.

For example, if a staged rebalance leaves 6 tokens unfilled and you intend to swap that remainder, first verify the order’s final state and available balance. On Biswap exchange, that check matters before routing the replacement trade: an order still eligible to fill can compete for the same inventory you expect to use.

Why can a fill land while cancellation is pending?

A fill and a cancellation are competing state changes, and the chain’s transaction ordering decides which takes effect first. If a filler’s transaction executes before the cancellation, that fill can succeed; if cancellation executes first and invalidates the order, a later fill should fail its validity check.

On an EVM chain, “submitted” does not mean “final.” A transaction can sit in the mempool, be replaced with a higher-fee transaction using the same sender nonce, or be included after another transaction that changes the order state. A wallet’s pending indicator is therefore weaker evidence than a confirmed transaction receipt plus an order status that reflects the resulting state.

The mechanism varies by order design. A contract-held order may be canceled through a state-changing call, while a signed order can remain offchain and be invalidated through a nonce, hash, or filled-amount check. CoW Protocol’s limit-order documentation distinguishes an API cancellation from an onchain cancellation, illustrating why the cancel button alone does not identify the guarantee you have.

What happens to the tokens and fees?

Token availability depends on how the order was funded. If assets were escrowed in a contract, the unfilled balance may need to be released or claimed after cancellation; if the order uses an allowance or signature without escrow, the tokens may have remained in your wallet, though that authorization can still permit a fill until invalidated.

Cancellation is not necessarily free. A cancellation transaction that writes to an EVM chain consumes gas, with the cost set by current network demand and transaction complexity; an offchain cancellation may have no direct chain fee but can provide a weaker guarantee until the protocol or settlement mechanism records it. Check whether you are paying for an immediate onchain invalidation, a service request, or only a user-interface action.

Do not assume cancellation reverses gas, protocol fees, or price exposure from the already-filled portion. If the order filled 40% before cancellation, that executed quantity remains a trade, and any fee associated with it is governed by the order’s fee rules. Reconcile the actual fill amount and returned or still-available balance before calculating the replacement order size.

How should you cancel quickly and verify the result?

Use the cancellation path that invalidates the order at the layer where fills are authorized, then verify that state before reusing the remainder. A fast offchain request can clear a displayed order quickly, but if the protocol supports an onchain invalidation and a fill race matters, the confirmed onchain state is the meaningful checkpoint.

  1. Record the order ID or hash, the filled amount, and the remaining amount before canceling.
  2. Submit cancellation and monitor its status; if it is an EVM transaction, confirm inclusion and check for a revert.
  3. Refresh the order’s authoritative status and confirm the remainder is no longer fillable.
  4. Check token balances and allowances, then size any replacement trade from the balance actually available.

A practical edge case is a cancel transaction that remains pending while the market moves toward your limit. Speeding it up can reduce the window, but replacement works only if the wallet uses the same sender and nonce; sending a second cancel with a different nonce may leave both transactions competing. The next step is to verify the order state and balance together, then route only the confirmed residual amount.

Top comments (0)