> For the complete documentation index, see [llms.txt](https://docs.defx.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.defx.com/docs/trade/defx-perp-dex/self-trade-prevention.md).

# Self Trade Prevention

Defx's self trade prevention mechanism prevents traders from matching their own orders on the order book, thereby ensuring that trading activities reflect genuine market interest rather than manipulated volume.

There are three possible actions that Defx can take if an order could create a self-trade

`EXPIRE_TAKER` - This mode prevents a trade by immediately expiring the taker order's quantity.

`EXPIRE_MAKER` - This mode prevents a trade by immediately expiring the potential maker order's quantity.

`EXPIRE_BOTH` - This mode prevents a trade by immediately expiring both the taker and the potential maker orders' quantities.

The STP event will occur depending on the STP mode of the **taker order**.

*Please note: These parameters are passed as part of the* [*Create Order API*](https://api-docs.defx.com/#8a5c210b-4027-4cc0-addf-6726e7f5acfc)*. While making a Create Order request, if you do not explicitly pass a value for stp as part of the request being made, Defx assigns a default stp mode to be* `EXPIRE_TAKER`&#x20;

\ <br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.defx.com/docs/trade/defx-perp-dex/self-trade-prevention.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
