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

# Grid engine

> The grid-trading engine at the core of Perps Agent.

The grid engine is the part of Perps Agent that actually trades. It turns a committed strategy config into a stream of orders on a venue and tracks the live state.

<Frame>
  <img src="https://mintcdn.com/perpsagent/R-DvtAh5TjBSOYGS/images/image.png?fit=max&auto=format&n=R-DvtAh5TjBSOYGS&q=85&s=9133953ea37cfc63019776da14e9680e" alt="Image" width="1280" height="720" data-path="images/image.png" />
</Frame>

## What a grid is

A grid strategy places **laddered buy and sell orders** at fixed intervals around a price range. When price oscillates inside the range, the engine harvests the spread between fills. The grid wins on volatility and pays for it during trends.

## How it works

A ladder of resting buy & sell limit orders that profits from ordinary price swings — **no forecast needed**.

<Steps>
  <Step title="Set range & grid">
    Split a price band into evenly spaced levels.
  </Step>

  <Step title="Buy below price">
    Resting **BUY** limits sit on every level under the mark.
  </Step>

  <Step title="Sell one level up">
    Each filled buy auto-places a take-profit **SELL** one level higher.
  </Step>

  <Step title="Repeat 24/7">
    Sideways chop = continuous round-trip profits.
  </Step>
</Steps>

<Note>
  **Buy limit** (below price) — opens long, closes short. **Sell limit** (above price) — opens short, closes long. Best in ranging / volatile markets · pre-committed on Mantle, executed on Bybit · fully automated.
</Note>

## What the engine does

* **Generates the ladder** from the committed config: range, step size, order count, and notional per level.
* **Places and refills orders** through the exchange adapter as fills arrive.
* **Tracks live state**: inventory, realized PnL, unrealized PnL, drawdown, and risk metrics.
* **Enforces caps**: hard stops on max drawdown, max leverage, and max position size.
* **Reports outcomes** to the proof layer at the end of every run.

## What it does *not* do

* It does not invent its own parameters — those come from the AI loop and are committed on-chain.
* It does not move funds — capital stays on the venue under user keys.
* It does not edit the track record — only the proof layer writes history.

<Tip>
  The grid engine is deliberately boring. All the "smart" decisions live in the AI agent loop, and all the trust lives in the Mantle proofs.
</Tip>
