Self trade prevention modes (STP modes)

What is self-trade prevention?

Self Trade Prevention ("STP") is a mechanism implemented to prevent users from inadvertently executing trades with their orders. This feature maintains a fair and transparent trading environment.

STP is activated when a user's active (taker) orders match with their passive orders in the depth book.

In the case of LayerAkira exchange, STP is designed to prevent the matching of orders that belong to the same trade group. Currently, this trade group is identified by the signer of the order. Essentially, this means that if two orders – whether active or passive – are signed by the same entity, they are considered part of the same trade group, and STP mechanisms will prevent these orders from being matched with each other.

Please note:

  • STP is only supported for the Ecosystem Book, not the Router Book

  • STP is not supported with the flag full-fill-only when the full amount of the taker order should be matched

What are the STP modes?

When STP is activated, there are four possible actions:

  1. NONE: The order is not subject to STP. It will be executed even if it matches the user's own order.

  2. EXPIRE_TAKER: The taker order is EXPIRED immediately if it would result in a self-trade.

  3. EXPIRE_MAKER: The maker orders are EXPIRED immediately if it would result in a self-trade.

  4. EXPIRE_BOTH: Both the taker and maker orders are EXPIRED immediately to prevent a self-trade.

The STP mode will be determined by what is activated in the taker's order in the Ecosystem Book

What is trade flow when STP occurs?

When STP is triggered, the trade flow varies depending on the specific STP mode set. Here's how it works for each mode:

NONE:

Trades are processed as usual. There is no STP intervention even if the orders belong to the same trade group ID.

This mode is useful if the client running different strategies on the different trading accounts associated with the same trading group.

EXPIRE_TAKER

If the taker's order matches with their own order, the remaining quantity of the taker's order becomes invalid. Consequently, no trade occurs with these remaining quantities. In such cases, users will receive the fills steam execution report' with the status EXPIRED, along with the quantity representing the remaining amount that was expired due to STP.

EXPIRE_MAKER

No trades will occur with makers' orders belonging to the same trade group ID. The remaining quantities of these makers' orders become invalid, and the orders are removed from the order book. Users will receive an 'execution report' indicating the status as EXPIRED, along with the quantity representing the remaining amount that expired due to STP for each maker order. This implies that the taker order will bypass its own market orders, leading to their expiration, and will instead be matched with orders positioned after them.

EXPIRE_BOTH

No trades will occur with makers' orders that belong to the same trade group ID. The remaining quantities of these makers' orders become invalid, and the orders are subsequently removed from the order book. Additionally, the remaining quantities of the taker's order also expire once a match with a maker order of the same trade group ID occurs.

Users will receive an 'execution report' indicating the status as EXPIRED. This report will include the quantity representing the remaining amount that expired due to STP for each maker order, as well as for the taker order. Consequently, this means that the taker order will avoid matching with its own market orders, resulting in their expiration.

Smart contract semantic

Semantic in smart contract reflect STP as follows:

If the signer of the taker and maker orders match when the STP of the taker is set not to NONE the trade will be invalid causing execution to fail.

Last updated