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

# CLOB Order Types

> Understanding limit and market orders in Vita CLOB

export const ConceptCard = ({concept, size = 'medium'}) => {
  const concepts = {
    'capital-efficiency': {
      title: 'Capital Efficiency',
      visual: '📊',
      description: 'Concentrate liquidity where it matters most',
      colorClass: 'text-green-600 dark:text-green-400',
      bgColorClass: 'bg-green-600/10',
      borderColorClass: 'border-green-600/30',
      icon: '📊',
      details: 'By providing liquidity only within a specific price range, your capital works harder and earns more fees per dollar invested.',
      example: 'Example: Concentrated positions can be significantly more capital efficient than traditional AMMs.'
    },
    'impermanent-loss': {
      title: 'Impermanent Loss',
      visual: '±%',
      description: 'Risk when price moves outside your range',
      colorClass: 'text-amber-600 dark:text-amber-400',
      bgColorClass: 'bg-amber-600/10',
      borderColorClass: 'border-amber-600/30',
      icon: '⚠️',
      details: 'The temporary loss of funds that occurs when providing liquidity due to price divergence. Becomes permanent when you withdraw.',
      example: 'Example: If ETH price doubles, you might have 5.7% less value than just holding.'
    },
    'fee-earnings': {
      title: 'Fee Earnings',
      visual: '0.30%',
      description: 'Earn from every trade in your range',
      colorClass: 'text-blue-600 dark:text-blue-400',
      bgColorClass: 'bg-blue-600/10',
      borderColorClass: 'border-blue-600/30',
      icon: '💰',
      details: 'Liquidity providers earn 35% of the 0.30% trading fee from all swaps that occur within their selected price range.',
      example: 'Example: $1M daily volume = $3,000 fees, LPs get $1,050.'
    },
    'price-range': {
      title: 'Price Range',
      visual: '[$min, $max]',
      description: 'Your active liquidity zone',
      colorClass: 'text-[#fb8f5a]',
      bgColorClass: 'bg-[#fb8f5a]/10',
      borderColorClass: 'border-[#fb8f5a]/30',
      icon: '🎯',
      details: 'The upper and lower price boundaries where your liquidity is active. Narrower ranges mean higher concentration but more management.',
      example: 'Example: NEAR at $5, range $4.50-$5.50 = ±10% coverage.'
    },
    'liquidity-depth': {
      title: 'Liquidity Depth',
      visual: '$TVL',
      description: 'Total value locked in the pool',
      colorClass: 'text-purple-400 dark:text-purple-300',
      bgColorClass: 'bg-purple-400/10',
      borderColorClass: 'border-purple-400/30',
      icon: '🌊',
      details: 'The total amount of tokens available for trading at each price level. Deeper liquidity means less slippage for traders.',
      example: 'Example: $10M TVL = 0.3% slippage on $100k trades.'
    },
    'price-time-priority': {
      title: 'Price-Time Priority',
      visual: '1st → Last',
      description: 'Fair order matching algorithm',
      colorClass: 'text-[#fb8f5a]',
      bgColorClass: 'bg-[#fb8f5a]/10',
      borderColorClass: 'border-[#fb8f5a]/30',
      icon: '⚡',
      details: 'Best prices execute first, then earliest orders at the same price. This ensures fair and transparent order execution.',
      example: 'Example: Buy at $5.00 placed first executes before buy at $5.00 placed later.'
    }
  };
  const data = concepts[concept] || concepts['capital-efficiency'];
  const sizeClasses = {
    small: 'p-4',
    medium: 'p-6',
    large: 'p-8'
  };
  const visualSizes = {
    small: 'text-2xl',
    medium: 'text-3xl',
    large: 'text-4xl'
  };
  const cardClasses = `
    ${sizeClasses[size]}
    ${data.bgColorClass}
    ${data.borderColorClass}
    border-2
    rounded-sm
    transition-all
    duration-300
    flex
    flex-col
    justify-center
    items-center
    text-center
    relative
    overflow-hidden
  `;
  return <div className={cardClasses} aria-label={`${data.title} concept card`}>
      {}
      <div className="text-3xl mb-2" aria-hidden="true">{data.icon}</div>
      
      {}
      <div className={`${visualSizes[size]} font-bold mb-2 ${data.colorClass}`} aria-label={data.visual}>
        {data.visual}
      </div>
      
      {}
      <h4 className="text-lg font-semibold mb-2 text-gray-900 dark:text-white">{data.title}</h4>
      
      {}
      <p className="text-sm text-gray-600 dark:text-gray-400 mb-3">{data.description}</p>
      
      {}
      {(size === 'large' || size === 'medium') && <div className="mt-4 pt-4 border-t border-gray-200 dark:border-gray-700">
          <p className="text-xs text-gray-500 dark:text-gray-500 leading-relaxed">
            {data.details}
          </p>
        </div>}
      
      {}
      {concept === 'capital-efficiency' && <div className="mt-4">
          <div className="h-2 bg-gray-100 dark:bg-gray-900 rounded-full overflow-hidden">
            <div className="h-full bg-gradient-to-r from-[#fb8f5a] to-[#ffaf85]" style={{
    width: '75%'
  }} role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" aria-label="75% efficiency compared to full range"></div>
          </div>
          <p className="text-xs text-gray-500 dark:text-gray-500 mt-1">Efficiency vs Full Range</p>
        </div>}
      
      {concept === 'fee-earnings' && <div className="mt-4 flex justify-center items-center space-x-2 text-xs">
          <span className="bg-gray-100 dark:bg-gray-900 px-2 py-1 rounded-sm">LPs: 35%</span>
          <span className="bg-gray-100 dark:bg-gray-900 px-2 py-1 rounded-sm">Protocol: 65%</span>
        </div>}
    </div>;
};

Vita CLOB supports two fundamental order types that cater to different trading strategies and needs.

<CardGroup cols={2}>
  <Card title="Limit Orders" icon="bullseye" href="#limit-orders">
    Execute at your specified price or better
  </Card>

  <Card title="Market Orders" icon="bolt" href="#market-orders">
    Execute immediately at best available price
  </Card>
</CardGroup>

## Limit Orders

Limit orders allow you to specify the exact price at which you want to buy or sell tokens. These orders are added to the order book and wait for a matching order at your specified price.

### How Limit Orders Work

<Frame caption="Limit order placement form">
  <img className="block dark:hidden" src="https://mintcdn.com/vita-29cb4832/0BX7ec2JKnkM5V86/images/screenshots/clob-place-order-form.png?fit=max&auto=format&n=0BX7ec2JKnkM5V86&q=85&s=cfca0caf8933de084a2ab9e17b654ef3" alt="Place Order Form" width="1014" height="1310" data-path="images/screenshots/clob-place-order-form.png" />

  <img className="hidden dark:block" src="https://mintcdn.com/vita-29cb4832/0BX7ec2JKnkM5V86/images/screenshots/clob-place-order-form.png?fit=max&auto=format&n=0BX7ec2JKnkM5V86&q=85&s=cfca0caf8933de084a2ab9e17b654ef3" alt="Place Order Form" width="1014" height="1310" data-path="images/screenshots/clob-place-order-form.png" />
</Frame>

<Tabs>
  <Tab title="Buy Limit Order">
    A buy limit order will only execute at or below your specified price.

    **Example:**

    * Current market price: 5.00 USDC
    * Your limit price: 4.95 USDC
    * Result: Order waits in order book until price drops to 4.95 or below
  </Tab>

  <Tab title="Sell Limit Order">
    A sell limit order will only execute at or above your specified price.

    **Example:**

    * Current market price: 5.00 USDC
    * Your limit price: 5.05 USDC
    * Result: Order waits in order book until price rises to 5.05 or above
  </Tab>
</Tabs>

### Limit Order Structure

```rust theme={null}
// Order parameters for limit orders
{
    market_id: u64,              // Market identifier
    price: U128,                 // Your specified price
    quantity: U128,              // Amount to trade
    is_buy: bool,                // true for buy, false for sell
    match_limit: u32             // Maximum number of matches (default: 50)
}
```

### Benefits of Limit Orders

* **Price Control**: Trade only at your desired price
* **No Slippage**: Price is guaranteed if order executes
* **Partial Fills**: Orders can be partially filled over time
* **Order Book Visibility**: Your order becomes part of market liquidity

## Market Orders

Market orders execute immediately at the best available price in the order book. They provide certainty of execution but not certainty of price.

### How Market Orders Work

<Steps>
  <Step title="Order Placement">
    Specify only the quantity you want to trade - no price needed
  </Step>

  <Step title="Price Matching">
    System automatically matches with best available orders:

    * Buy orders match with lowest asks
    * Sell orders match with highest bids
  </Step>

  <Step title="Execution">
    Order executes immediately, potentially at multiple price levels
  </Step>
</Steps>

### Market Order Structure

```rust theme={null}
// Order parameters for market orders
{
    market_id: u64,              // Market identifier
    quantity: U128,              // Amount to trade
    is_buy: bool,                // true for buy, false for sell
    match_limit: u32             // Maximum number of matches (default: 50)
}
```

### Benefits of Market Orders

* **Immediate Execution**: No waiting for price to reach your level
* **Simplicity**: Only need to specify quantity
* **Complete Fills**: Usually fills entire order amount
* **Time Priority**: Executes before any new limit orders

<Warning>
  Market orders may experience price slippage in low liquidity conditions. Always check order book depth before placing large market orders.
</Warning>

## Order Matching Rules

### Price-Time Priority

Orders are matched according to strict price-time priority:

1. **Price Priority**: Best prices are matched first
   * Highest bid matches with lowest ask
   * Orders at better prices always execute before worse prices

2. **Time Priority**: For orders at the same price
   * Earlier orders (by timestamp) execute first
   * First-in, first-out (FIFO) within each price level

<Frame caption="Order book showing price-time priority">
  <img className="block dark:hidden" src="https://mintcdn.com/vita-29cb4832/0BX7ec2JKnkM5V86/images/screenshots/clob-orderbook-view.png?fit=max&auto=format&n=0BX7ec2JKnkM5V86&q=85&s=951aafba2c11f4672b069cc85f88c3be" alt="Order Book View" width="2942" height="1878" data-path="images/screenshots/clob-orderbook-view.png" />

  <img className="hidden dark:block" src="https://mintcdn.com/vita-29cb4832/0BX7ec2JKnkM5V86/images/screenshots/clob-orderbook-view.png?fit=max&auto=format&n=0BX7ec2JKnkM5V86&q=85&s=951aafba2c11f4672b069cc85f88c3be" alt="Order Book View" width="2942" height="1878" data-path="images/screenshots/clob-orderbook-view.png" />
</Frame>

### Matching Constraints

<Note>
  Each order can match with a maximum of 50 counter-orders per execution to prevent excessive gas consumption
</Note>

### Self-Trade Prevention

The system prevents users from trading with their own orders:

* Buy and sell orders from the same account cannot match
* Prevents wash trading and maintains market integrity

## Order Lifecycle

<Steps>
  <Step title="Submission">
    Order validated and added to order book (limit) or matched immediately (market)
  </Step>

  <Step title="Matching">
    System continuously matches compatible orders based on price-time priority
  </Step>

  <Step title="Partial Fills">
    Orders may be partially filled if insufficient liquidity at desired price
  </Step>

  <Step title="Completion">
    Order removed from book when fully filled or cancelled
  </Step>
</Steps>

## Choosing Order Type

### Use Limit Orders When:

* You have a specific price target
* You're not in a rush to execute
* You want to avoid slippage
* You're providing liquidity to the market

### Use Market Orders When:

* You need immediate execution
* You're trading liquid pairs
* Small price differences don't matter
* You want to ensure your order fills

## Order Type Comparison

| Feature               | Limit Order     | Market Order    |
| --------------------- | --------------- | --------------- |
| **Price Control**     | ✓ Exact price   | ✗ Market price  |
| **Execution Speed**   | May take time   | Immediate       |
| **Slippage**          | None            | Possible        |
| **Partial Fills**     | Common          | Less common     |
| **Order Book Impact** | Adds liquidity  | Takes liquidity |
| **Best For**          | Patient traders | Urgent trades   |

## Next Steps

<CardGroup cols={2}>
  <Card title="Place Orders" icon="plus" href="/clob/place-orders">
    Learn how to place your first order
  </Card>

  <Card title="Manage Orders" icon="list" href="/clob/manage-orders">
    Track and manage your open orders
  </Card>
</CardGroup>
