Self Trade Prevention (STP)
Self Trade Prevention (STP) is a mechanism that prevents traders from executing trades against their own orders. This feature helps maintain market integrity and avoid unintentional self-trading scenarios.
Overview
When placing orders, you can 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
You can specify the STP mode when placing any type of order:
- Limit orders
- Market orders
- Stop-limit orders
- Stop-market orders
- OCO orders (One Cancels Other)
- Collateral orders
Example
{
"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
(Limit orders) - POST
/api/v4/order/market
(Market orders) - POST
/api/v4/order/stock_market
(Stock market orders) - POST
/api/v4/order/stop_limit
(Stop-limit orders) - POST
/api/v4/order/stop_market
(Stop-market orders) - POST
/api/v4/order/collateral/market
(Collateral market orders) - POST
/api/v4/order/collateral/stop-limit
(Collateral stop-limit orders) - POST
/api/v4/order/collateral/trigger-market
(Collateral trigger market orders) - POST
/api/v4/order/collateral/oco
(Collateral OCO orders)
Best Practices
- Default Behavior: If you don’t specify an STP mode, the system defaults to
no
, allowing self-trades. - Risk Management: For automated trading systems or when running multiple strategies, it’s recommended to use
cancel_both
orcancel_new
to prevent unintentional self-trades. - Market Making: When running market making strategies, consider using
cancel_new
to maintain existing orders’ queue position.
Response Handling
When an order is affected by STP rules, the order response will include the stp
field indicating the mode that was applied. 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