# Position PnL Calculator

> Position PnL Calculator is a paid API for AI agents from api.24klabs.ai, paid per call via x402, $0.003/call, status unknown (last checked 2026-09-15).

Calculates realized profit/loss, ROI percentage, and break-even price for a trading position given entry/exit prices, size, side, leverage, and fee rates.

## Facts

- Endpoint: POST https://api.24klabs.ai/api/v1/position-pnl-calculator
- Price: $0.003/call
- Payment: x402
- Status: unknown
- Last checked: 2026-09-15
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/position-pnl-calculator-46119aeb
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_ghdzzFMYzGZieYEidWeem

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability position-pnl-calculator-46119aeb -d '<json body>'
```

Example prompt: Calculate my realized PnL, ROI, and break-even price for a long position: I entered at $42,000 and exited at $45,500, size 0.5 BTC, 10x leverage, with a 0.04% taker fee and 0.02% maker fee.

## When to prefer this

Use this endpoint when you need a precise, fee-aware PnL calculation for a single closed or hypothetical position on any leveraged instrument — especially when taker/maker fee differentiation and leverage-adjusted ROI matter. Prefer this over manual calculations or generic spreadsheet formulas when integrating into an automated trading analysis or agent workflow.

## Known failure modes

- Missing required fields (entry price, exit price, size, side, leverage) return a 400 validation error
- Invalid side value (not long/short) returns an error
- Zero or negative leverage causes a computation error
- Fee rates out of expected range may produce warnings or errors
- Insufficient USDC balance for the $0.003 per-call fee results in a payment failure

## How this service works

Realized PnL, ROI %, and break-even for a position from entry, exit, size, side, leverage and taker/maker fee rate.

## Output

Returns the realized PnL in dollar terms, ROI as a percentage, and the break-even price at which the trade would have been neither profitable nor unprofitable, all accounting for the specified leverage and fee rates.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "properties": {
  "side": {
   "type": "string"
  },
  "size": {
   "type": "number"
  },
  "fee_rate": {
   "type": "number"
  },
  "leverage": {
   "type": "number"
  },
  "exit_price": {
   "type": "number"
  },
  "entry_price": {
   "type": "number"
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "type": "json",
 "example": {
  "net_pnl": 198.9,
  "roi_pct": 98.9,
  "gross_pnl": 200
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/position-pnl-calculator-46119aeb/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from api.24klabs.ai](https://www.zero.xyz/host/api.24klabs.ai/llms.txt)
