Self-Trade Prevention
GX Exchange implements expire-maker self-trade prevention (STP) to prevent a user’s orders from matching against each other.
Mechanism
When a new order would match against a resting order from the same account (including sub-accounts under the same master), the system cancels the resting (maker) order and allows the incoming (taker) order to continue matching against other orders in the book.
Why Expire-Maker
The expire-maker approach is chosen because:
- Preserves taker intent: The incoming order represents the trader’s most recent intention and is prioritized
- Removes stale quotes: The resting order may be a stale quote that the trader intended to cancel
- Market maker friendly: Market makers who update quotes frequently benefit from automatic removal of outdated resting orders
Detection Scope
Self-trade prevention applies across:
- Orders from the same address
- Orders from a master account and any of its sub-accounts
- Orders from different sub-accounts under the same master
This ensures that traders cannot circumvent STP by routing orders through different sub-accounts.
Behavior
| Scenario | Action |
|---|---|
| New buy order matches own resting sell | Resting sell is cancelled; buy continues matching |
| New sell order matches own resting buy | Resting buy is cancelled; sell continues matching |
| New order matches multiple own resting orders | All matching own resting orders are cancelled sequentially |
| New order matches own and others’ orders | Own orders are cancelled; others’ orders are filled normally |
Example
A market maker has the following resting orders:
- Sell 10 BTC at $60,100 (resting, order A)
- Sell 5 BTC at $60,200 (resting, order B)
The same market maker submits: Buy 20 BTC at $60,150
- The buy at $60,150 would match the sell at $60,100 (order A) — but same account, so order A is cancelled
- The buy continues to the next price level. $60,200 (order B) is above the buy limit of $60,150, so no match
- The buy order rests in the book at $60,150 with full size of 20 BTC
STP and Fees
When a resting order is cancelled due to STP:
- No trading fees are charged (no execution occurred)
- The cancelled order’s margin reservation is released
- The cancellation is logged as an STP event for audit purposes
Configuration
Self-trade prevention is always enabled and cannot be disabled. It is enforced at the consensus layer to ensure consistency across all validators.