# Take Profit/Stop Loss (/docs/risex/trading/tpsl)

## Overview

RISEx supports Take Profit (TP) and Stop Loss (SL) orders as conditional close orders. When a monitored price crosses the configured trigger level, the order is automatically executed on-chain as a reduce-only close.

The order is always **reduce-only**: it can only reduce an existing position and can never increase it.

***

## Order Types

**Take Profit (TP)** triggers when price moves favorably past a target level, locking in gains. **Stop Loss (SL)** triggers when price moves unfavorably past a threshold, capping a loss.

Trigger direction depends on the position side:

| Position         | Type        | Trigger Condition     |
| ---------------- | ----------- | --------------------- |
| Long (SELL side) | Take Profit | `price >= stop_price` |
| Long (SELL side) | Stop Loss   | `price <= stop_price` |
| Short (BUY side) | Take Profit | `price <= stop_price` |
| Short (BUY side) | Stop Loss   | `price >= stop_price` |

The side of the TP/SL order must always be opposite to the position side (SELL to close a long, BUY to close a short).

***

## Trigger Price Source

Each TP/SL order is tagged to one of two price feeds:

* **Last Traded Price**: triggers when a real trade on the orderbook crosses the stop price.
* **Mark Price**: triggers when the Stork oracle mark price crosses the stop price.

A mark-price order is only evaluated against oracle updates. A last-price order is only evaluated against real trades. They do not cross-trigger.

***

## Sizing Modes

### Full Size

The order always closes 100% of the current position. As the position changes, the order size adjusts automatically to match the full position at all times. This is the simplest and most beginner-friendly mode, and thus enabled by default on the UI.

### Fixed Size

The order closes a specific quantity of the position.

* The order size must not exceed the current position size at placement time.
* If the position partially closes and falls below the order size, the order is automatically clamped down to the remaining position size.
* The order size never increases even if the position grows.

### Proportional Size

The order closes a fixed fraction of the position and automatically tracks the position as it changes. On every position change (trade, partial fill, or any event that modifies the position), the new TP/SL order size is recalculated proportionally.

Full Size is a special case of Proportional Size with 100% proportion. Proportional Size mode is currently available only via APIs.

***

## Position Reconciliation

As positions change, active TP/SL orders are automatically reconciled to remain valid.

### Full Close or Position Flip

All active TP/SL orders (both ACCEPTED and TRIGGERED) are cancelled immediately. A reduce-only order placed against a closed or flipped position would revert on-chain, so cancellation happens proactively.

### Partial Close or Position Change (same direction)

* For **fixed-size** orders: any order whose size exceeds the remaining position is clamped down to the remaining size. The order stays active.

* For **proportional orders**: the order is re-sized proportionally to reflect the position change, in both directions (growth and reduction). For example, if the position grows (from an additional trade), proportional orders grow with it.

### Expiry

Orders placed with a time-in-force of GTT (Good Till Time) are automatically cancelled when they expire.

***

## Execution Type

When a TP/SL order is triggered, it is submitted to the orderbook as either a market order or a limit order configured by the user.

### Market Order

The order executes at whatever price is available at the time of trigger. It fills immediately at the best available price and there is no price guarantee: in fast-moving markets, the actual execution price may differ from the trigger price.

### Limit Order

The order executes only at the configured `limit_price` or better. This is the mechanism for controlling worst-case execution price (i.e., slippage protection).

If the market price is on the wrong side of `limit_price` at execution time, fill behavior depends on the time-in-force:

* **IOC**: unfilled remainder is cancelled immediately. The order may partially fill or not fill at all.
* **FOK**: the entire order must fill at once or it is cancelled entirely.
* **GTC**: the order rests on the book until it can fill at `limit_price` or better, or until cancelled.

There is no separate maximum slippage parameter. Slippage is controlled entirely by choosing a limit order and setting `limit_price` to the worst acceptable fill level.

***

## Delegation

TP/SL orders are executed automatically by RISEx when the trigger condition is met. For this to work, RISEx needs permission to submit a close order on the user's behalf without requiring the user to be online.

This permission is granted once, upfront, by signing a delegation message with the account wallet. The signed message authorizes a specific RISEx executor address to act on behalf of the account. RISEx registers this authorization on-chain, so it is verifiable and cannot be forged.
