Catalog/trade-pnl

Calculators

Trade profit & loss API

Trade PnL: grossPnl = (exit − entry)·units·(long?1:−1), net subtracts fees; returns return-on-position and return-on-margin (if leverage given). Deterministic accounting. Answers 'what's my profit','PnL on this trade','return on margin at 2x','did this trade win or lose'.

Price$0.01per request
MethodPOST
Route/v1/calc/trade-pnl
StatusLive
MIME typeapplication/json
Rate limit120/minute
CacheNo cache
calctradingpnlprofit-lossreturnfeesleverageaccounting
API URLhttps://x402.hexl.dev/v1/calc/trade-pnl
Integration docs
Example request
{
  "entry": 100,
  "exit": 110,
  "units": 50,
  "direction": "long",
  "fees": 5,
  "leverage": 2
}
Example response
{
  "entry": 100,
  "exit": 110,
  "units": 50,
  "direction": "long",
  "fees": 5,
  "grossPnl": 500,
  "netPnl": 495,
  "positionCost": 5000,
  "returnOnPositionPct": 9.9,
  "outcome": "win",
  "leverage": 2,
  "margin": 2500,
  "returnOnMarginPct": 19.8
}
Input schema
{
  "type": "object",
  "required": [
    "entry",
    "exit",
    "units"
  ],
  "properties": {
    "entry": {
      "type": "number",
      "examples": [
        100
      ]
    },
    "exit": {
      "type": "number",
      "examples": [
        110
      ]
    },
    "units": {
      "type": "number",
      "examples": [
        50
      ]
    },
    "direction": {
      "type": "string",
      "enum": [
        "long",
        "short"
      ],
      "default": "long"
    },
    "fees": {
      "type": "number",
      "default": 0,
      "examples": [
        5
      ]
    },
    "leverage": {
      "type": "number",
      "examples": [
        2
      ]
    }
  }
}
Output schema
{
  "type": "object",
  "additionalProperties": true
}