# SperaxOS Build Close Perpetual Position Transaction

> SperaxOS Build Close Perpetual Position Transaction is a paid API for AI agents from chat.sperax.io, paid per call via x402, $0.001/call, status unknown (last checked 2026-11-14).

Builds an unsigned close-position transaction for a perpetual futures position on GMX, Hyperliquid, or dYdX, specifying the percentage of the position to close.

## Facts

- Endpoint: POST https://chat.sperax.io/api/x402/tools/perpetuals/buildClosePositionTx?utm_source=zero.xyz
- Price: $0.001/call
- Payment: x402
- Status: unknown
- Last checked: 2026-11-14
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/speraxos-build-close-perpetual-position-transaction-f2ed46cc
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_ImBt5wXu471c60Jp6E-dV

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 speraxos-build-close-perpetual-position-transaction-f2ed46cc -d '<json body>'
```

Example prompt: Build a transaction to close 75% of my GMX perpetual position ID '0xabc123' for my wallet 0xDEAD...BEEF — I want to reduce my exposure without fully exiting.

## When to prefer this

Use this endpoint when an agent needs to programmatically generate an unsigned close-position transaction for perpetual futures on GMX, Hyperliquid, or dYdX without requiring an API key, paying per-call via x402. Prefer this over manual transaction construction when you need exchange-specific calldata built correctly for partial or full position closure.

## Known failure modes

- Invalid or unknown positionId — position not found on the specified exchange
- Unsupported exchange value outside the enum (gmx, hyperliquid, dydx)
- closeSizePercent outside valid range (1–100) — validation error
- Wallet address not associated with the given position — authorization mismatch
- Exchange API or on-chain data unavailable — service timeout or upstream error
- Payment of $0.001 USDC not provided or rejected — HTTP 402 response

## How this service works

SperaxOS is an AI-powered DeFi operating system — track portfolios, execute swaps, analyze on-chain data, and collaborate with intelligent agents that manage your crypto workflow.

## Output

Returns an unsigned transaction object (calldata, to address, value, etc.) that the caller can sign and broadcast to close the specified percentage of a perpetual futures position on the chosen DEX. No on-chain state is changed until the transaction is signed and submitted.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "properties": {
  "exchange": {
   "enum": [
    "gmx",
    "hyperliquid",
    "dydx"
   ],
   "type": "string",
   "description": "Exchange where position is held"
  },
  "positionId": {
   "type": "string",
   "description": "Position ID (from getPositions)"
  },
  "walletAddress": {
   "type": "string",
   "description": "Trader wallet address"
  },
  "closeSizePercent": {
   "type": "number",
   "maximum": 100,
   "minimum": 1,
   "description": "Percentage of position to close (1–100)"
  }
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/speraxos-build-close-perpetual-position-transaction-f2ed46cc/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from chat.sperax.io](https://www.zero.xyz/host/chat.sperax.io/llms.txt)
