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

# Closing Trades

Strike Protocol allows positions to be closed at any time at the current market price, with automatic settlement based on profitability and treasury balance.

## Dynamic Fee Structure

Fees are calculated dynamically based on:

* **Price movement magnitude**: Larger price moves incur lower fee percentages
* **Position size multiplier**: Prevents manipulation through position-based scaling
* **No fees on losing positions**: Only profitable trades are charged fees

## Position Lifecycle

Positions move through three distinct phases:

**Open** → **Closed** → **Settled**

* **Open**: Position is open with real-time PnL and funding accumulation
* **Closed**: Position is closed and profitable but treasury is insufficient to pay out immediately. Losing positions settle immediately
* **Settled**: Payout processed and funds transferred

## Settlement Process

### Payout Queue Flow

```mermaid theme={null}
graph TD
    A[Close Position] --> B{Profitable?}
    B -->|No| G{Positions Pending Payout?}
    B -->|Yes| C{Treasury Sufficient?}
    C -->|Yes| E[Process Payout]
    C -->|No| F[Enter Payout Queue]
    G -->|No| L[Add Loss to Treasury]
    G -->|Yes| H{Treasury Sufficient?}
    H -->|Yes| I[Process Payout]
```

## Emergency Exit

Retrieve your margin when a profitable position is stuck in the payout queue:

* Returns your original margin amount immediately
* Forfeits any profits from the position
* Removes position from the payout queue and settles it
* Useful when you need immediate liquidity

## Example Close Flows

<Tabs>
  <Tab title="Profitable - Immediate Settlement">
    ```
    Initial: Long BTC at 100,000 USD, 100 USD margin, 10x leverage

    1. BTC rises to 110,000 USD (10% increase)
    2. Click close position
    3. Price PnL: +100 USD (10% of 1,000 USD notional)
    4. Accumulated funding: -2 USD (paid over 8 hours)
    5. Dynamic fees: ~15 USD (based on price move)
    6. Net PnL: +83 USD
    7. Treasury check: Sufficient funds available
    8. Status: open → settled (skips closed status)
    9. Balance credited: 183 USD (100 margin + 83 profit)
    ```
  </Tab>

  <Tab title="Profitable - Queued Settlement">
    ```
    Initial: Long ETH at 3,000 USD, 500 USD margin, 5x leverage

    1. ETH rises to 3,300 USD (10% increase) 
    2. Click close position
    3. Price PnL: +250 USD (10% of 2,500 USD notional)
    4. Accumulated funding: +5 USD (received over 24 hours)
    5. Dynamic fees: ~35 USD
    6. Net PnL: +220 USD
    7. Treasury check: Insufficient funds
    8. Status: open → closed (enters payout queue)
    9. Queue position: 15,000 USD ahead
    10. Later: closed → settled when processed
    11. Balance credited: 720 USD (500 margin + 220 profit)
    ```
  </Tab>

  <Tab title="Closing with Loss">
    ```
    Initial: Short SOL at 100 USD, 200 USD margin, 20x leverage

    1. SOL rises to 102 USD (2% increase = 40% loss on short)
    2. Click close position
    3. Price PnL: -80 USD (2% loss on 4,000 USD notional)
    4. Accumulated funding: -5 USD (paid over 12 hours)
    5. Fees: 0 USD (no fees on losses)
    6. Net PnL: -85 USD
    7. Status: open → settled (immediate, no queue)
    8. Balance credited: 115 USD (200 margin - 85 loss)
    ```
  </Tab>
</Tabs>
