> ## Documentation Index
> Fetch the complete documentation index at: https://docs.whitebit.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Self Trade Prevention (STP)

> Self Trade Prevention (STP) is a mechanism to prevent traders from executing trades against the same trader's orders. The feature helps maintain market integrity and avoid unintentional self-trading scenarios.

## Overview

When placing [orders](/glossary#orders), specify how the system should handle potential self-trades using the `stp` parameter. This parameter determines the behavior when an order would match against another order from the same account.

## STP Modes

The following STP modes are available:

| Mode          | Description                                                           |
| ------------- | --------------------------------------------------------------------- |
| `no`          | Default mode. Self-trades are allowed                                 |
| `cancel_both` | Both the new order and the existing order will be canceled            |
| `cancel_new`  | The new order will be canceled, and the existing order will remain    |
| `cancel_old`  | The existing order will be canceled, and the new order will be placed |

## Usage

Specify the STP mode when placing any type of order:

* [Limit orders](/glossary#limit-order)
* [Market orders](/glossary#market-order)
* [Stop-limit orders](/glossary#stop-limit-order)
* [Stop-market orders](/glossary#stop-market-order)
* [OCO orders](/glossary#oco-orders) (One Cancels Other)
* [Collateral orders](/glossary#collateral)

### Example

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "market": "BTC_USDT",
  "side": "buy",
  "amount": "0.001",
  "price": "40000",
  "stp": "cancel_both"  // STP mode specification
}
```

## Supported Endpoints

STP is supported on the following API endpoints:

* [POST `/api/v4/order/new`](/api-reference/spot-trading/overview#create-limit-order) (Limit orders)
* [POST `/api/v4/order/market`](/api-reference/spot-trading/overview#create-market-order) (Market orders)
* [POST `/api/v4/order/stock_market`](/api-reference/spot-trading/overview#create-buy-stock-market-order) (Stock market orders)
* [POST `/api/v4/order/stop_limit`](/api-reference/spot-trading/overview#create-stop-limit-order) (Stop-limit orders)
* [POST `/api/v4/order/stop_market`](/api-reference/spot-trading/overview#create-stop-market-order) (Stop-market orders)
* [POST `/api/v4/order/collateral/market`](/api-reference/collateral-trading/overview#collateral-market-order) (Collateral market orders)
* [POST `/api/v4/order/collateral/stop-limit`](/api-reference/collateral-trading/overview#collateral-stop-limit-order) (Collateral stop-limit orders)
* [POST `/api/v4/order/collateral/trigger-market`](/api-reference/collateral-trading/overview#collateral-trigger-market-order) (Collateral trigger market orders)
* [POST `/api/v4/order/collateral/oco`](/api-reference/collateral-trading/overview#create-collateral-oco-order) (Collateral OCO orders)

## Best Practices

1. **Default Behavior**: If no STP mode is specified, the system defaults to `no`, allowing self-trades.
2. **Risk Management**: For automated trading systems or when running multiple strategies, it's recommended to use `cancel_both` or `cancel_new` to prevent unintentional self-trades.
3. **Market Making**: When running [market making](/glossary#maker) strategies, consider using `cancel_new` to maintain existing orders' queue position.

## Response Handling

When an order is affected by STP rules, the order response includes the `stp` field indicating the applied mode. The order status will reflect the outcome based on the STP mode:

* Orders canceled due to STP will have a "CANCELED" status
* Successfully placed orders will proceed with normal status progression
