# Perpvacy for agents

For AI agents. Perpvacy runs leveraged perp strategies from a trading account that cannot be linked
to its owner's wallet. You describe a trade as a rule; the server watches the market and executes it.

API base: `https://app.perpvacy.xyz/api/agent` · JSON in, JSON out.

You can arm, stop and close. You can **not** deposit, send or withdraw: no such route exists for
agent keys. Your owner sets your limits (margin, leverage, coins, daily loss, stop loss required).

## 1. Get a key

- **From your owner:** they create one in the app (Agents page) and give it to you: `pvk_…`.
- **Practice:** `POST /register` with `{"name": "3-40 chars", "made_by": "your model"}` returns
  `{"key"}` with pretend money at live prices. Only works while the server is in practice mode.

Send the key on every call: `Authorization: Bearer pvk_…`. 60 requests a minute.

## 2. Look around

- `GET /me` → mode (paper or live), free balance, your limits, `canArm`.
- `GET /market` → coins you may trade: mid, funding (% per hour), 24h change, max leverage.
- `GET /schema` → JSON schema of a rule, with notes on units.

## 3. Make a rule

Either `POST /parse` with `{"text": "If ETH drops 5% in a day, long 3x with $100, stop at -6%"}`
and use the `rule` it returns, or build one yourself:

```json
{
  "name": "ETH dip",
  "conditions": [{"kind": "price_change", "coin": "ETH", "pct": -5, "windowMinutes": 1440}],
  "action": {"type": "open", "coin": "ETH", "side": "long", "sizeUsd": 100, "leverage": 3},
  "stopLossPct": 6,
  "takeProfitPct": 15,
  "repeat": "once",
  "cooldownMinutes": 60
}
```

`sizeUsd` is margin; the position is `sizeUsd × leverage`. Condition kinds: `price_above`,
`price_below`, `price_change`, `funding_above`, `funding_below`, `wallet_opens`,
`fear_greed_below`, `fear_greed_above`, `x_post`. All conditions must hold at once.

## 4. Arm it and watch

- `POST /strategies` with `{"rule": {...}, "text": "optional original wording"}` → the armed strategy.
  A refusal says which limit it broke.
- `GET /strategies` → status and the latest check of each condition.
- `GET /positions` → entry, mark, liquidation price, PnL, fees, funding.
- `POST /strategies/<id>/stop` → kill switch: stop and close what it opened.
- `POST /positions/<id>/close` → close one position at market.
- `GET /exposure` → privacy score for the funding trail, with fixes. No addresses.

## MCP

The same actions as MCP tools (`perpvacy_me`, `perpvacy_parse_rule`, `perpvacy_arm`, …):

```
PERPVACY_API_URL=https://app.perpvacy.xyz PERPVACY_AGENT_KEY=pvk_… npx tsx server/src/agent/mcp.ts
```

## Rules of the house

- Always read `/me` first. If `mode` is `live`, the money is real.
- Positions are public on the exchange. What is private is who they belong to.
- Leverage can lose the whole margin. Use a stop loss; your key may require one.
