# Self-Trade Prevention

> How your resting orders are cancelled when an incoming order would trade with your own account, including across YES and NO.

Your orders cannot fill against another order from the same account. This
applies to ordinary BUY/SELL trades and to
[cross-orderbook matching](/docs/cross-orderbook-matching): BUY YES with BUY NO
(`MINT`), and SELL YES with SELL NO (`MERGE`). Prevention is always enabled;
there is no option to change which order is cancelled or to turn it off.

## What happens on a self-match [#what-happens-on-a-self-match]

When an incoming taker order would match a resting maker order owned by the
same account:

1. The **maker order's entire remaining quantity is cancelled**, even if the
   incoming order is smaller. Any earlier fills remain completed.
2. A cancelled BUY releases its reserved buying capacity; a cancelled SELL
   unlocks its outcome tokens.
3. An [account stream](/docs/account-stream) `order_cancelled` event is emitted
   with reason `SELF_TRADE_PREVENTION`.
4. The taker order continues matching against the next eligible resting order,
   if any. Self-trade prevention does not itself cancel the taker.

This means a taker order that would have matched only your own resting
orders effectively cancels those resting orders and then rests on the book
(if the time-in-force allows) or has its unfilled remainder cancelled.

Only eligible orders encountered while matching are cancelled. Orders outside
the incoming limit, or orders not reached because the incoming order is already
filled, remain in place. Orders are encountered by effective price, then arrival
time, across both outcomes. A better-priced order from another account can fill
your incoming order before it reaches your own quote.

## Cross-outcome examples [#cross-outcome-examples]

Assume there is no other eligible liquidity and each incoming order is `GTC`:

| Your resting order          | Your incoming order         | Result                                                                                   |
| --------------------------- | --------------------------- | ---------------------------------------------------------------------------------------- |
| BUY NO, 100 shares at 0.40  | BUY YES, 50 shares at 0.70  | The NO order is cancelled for its full remaining 100 shares; the YES order rests at 0.70 |
| SELL NO, 100 shares at 0.60 | SELL YES, 50 shares at 0.30 | The NO order is cancelled and its 100 shares unlocked; the YES order rests at 0.30       |

Both orders in a potential self-match can be BUYs, or both can be SELLs. Having
different outcome token IDs does not prevent a self-match. No pair is created
or combined in these examples, and no trading fee is charged for the prevented
match. Use [split or merge](/docs/on-chain/positions) to change your own paired
inventory directly.

If another account has eligible liquidity behind your cancelled order, the
incoming order can fill against it and normal fees apply to that actual trade.

## FOK and post-only orders [#fok-and-post-only-orders]

A FOK order is checked against non-self liquidity before the book changes. If
there is not enough to fill the complete order, the FOK is rejected and your
resting orders remain in place. This check includes eligible liquidity on both
outcomes when cross-orderbook matching is enabled; your own orders never count
toward the required quantity.

Post-only checks also include eligible complementary liquidity from other
accounts. For example, your post-only BUY YES at 0.70 would take another
account's BUY NO at 0.40, so it is rejected even with no YES asks.

If the only eligible order belongs to you, it does not count as a taker fill.
The post-only order can be accepted, cancel your older resting order through
self-trade prevention, and then rest. Post-only protects you from taking
liquidity; it does not preserve your older quotes.

## Implications [#implications]

* A prevented self-match incurs no trading fee.
* A self-match never produces a fill — it never appears in your
  [trade history](/docs/portfolio) and never contributes to trading-volume
  metrics.
* Track your quotes across both YES and NO. An aggressive order can cancel
  your resting order on either outcome, including one with the same BUY/SELL
  side as the incoming order.

## How to detect it programmatically [#how-to-detect-it-programmatically]

The `order_cancelled` event on the [account stream](/docs/account-stream)
carries `reason = "SELF_TRADE_PREVENTION"`. Treat this the same as any other
cancellation: the resting order is gone, and you may re-place it if needed.
