Skip to main content

Self-Trade Prevention (STP)

Automatic protection against self-trading.

Overview​

When an incoming (taker) order would match against a resting (maker) order from the same wallet, the engine cancels both orders instead of filling them. This prevents wash trading and protects market makers from accidentally crossing their own quotes.

STP is always active. There is no configuration, no opt-out, and no alternative modes.

Behavior​

Strategy: Cancel Both​

When a self-trade is detected:

  1. Maker order is cancelled with reason "Self-trade prevention"
  2. Taker order is rejected (if no prior fills) or cancelled (if partially filled)

No fill is generated between the two orders.

Wallet-Level Matching​

STP compares wallet addresses, not agent keys. If you use agent authorization to sign orders from multiple keys, all orders under the same trading wallet are subject to STP against each other.

Partial Fills Are Preserved​

If a taker order fills against other counterparties before encountering a self-trade, those fills are kept.

Example: The book has 5 contracts offered by Wallet B, then 5 contracts offered by Wallet A. Wallet A submits a buy for 10 contracts:

StepMatch AgainstResult
1Wallet B (5 contracts)Fill: 5 contracts executed
2Wallet A (5 contracts)Self-trade detected

Outcome:

  • Wallet A receives a fill for 5 contracts against Wallet B
  • Wallet A's maker order (5 contracts) is cancelled
  • Wallet A's taker order is cancelled with filled_size: 5

Order Status​

ScenarioTaker StatusReason
No prior fillsREJECTED"Self-trade prevention"
Partial fills before self-tradeCANCELED"Self-trade prevention (partial fill kept)"

The maker order is always CANCELED with reason "Self-trade prevention".

GTC Orders Do Not Rest After Self-Trade​

If a GTC taker order triggers STP, the remaining quantity is not added to the book, even if the order would normally rest. The order is fully terminated.

WebSocket Notifications​

Both the taker and maker cancellation/rejection are delivered on the order_updates channel. The reason field indicates STP was the cause.

FAQ​

Can I choose a different STP mode (e.g., cancel-newest or decrement)? No. Hypercall uses cancel-both exclusively.

Does STP apply to perp orders? No. Hypercall STP applies to orders matched on Hypercall's book: options and combo orders. Perp orders match on Hyperliquid's order book, where Hyperliquid's own self-trade rules apply.

What happens to a fill-or-kill (FOK) order that reaches its own resting order? A FOK order fills its complete size or nothing. Liquidity behind your own resting order does not count toward that size. If STP would stop the FOK order before it fills completely, the FOK order is rejected with reason "Fill-or-kill order cannot fill its complete quantity". Nothing executes, and your resting order stays on the book. If the FOK order fills completely before it reaches your resting order, STP does not trigger.

Does STP apply to combo orders? Yes. Matching stops before a combo or implied route would trade an account against itself, and the resting maker order is cancelled. See the Experimental Combo API for the all-or-nothing cases (FOK and atomic replace).

Does STP apply to RFQ trades? Yes. If the taker and a quote provider share the same wallet, the quote is rejected.

I'm a market maker quoting both sides. Will my quotes cancel each other? Only if an incoming order would cause them to cross. Resting orders on opposite sides of the book at different prices coexist normally. STP only triggers at match time.