{"uid":"cap_ImBt5wXu471c60Jp6E-dV","slug":"speraxos-build-close-perpetual-position-transaction-f2ed46cc","name":"SperaxOS Build Close Perpetual Position Transaction","description":"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.","url":"https://chat.sperax.io/api/x402/tools/perpetuals/buildClosePositionTx?utm_source=zero.xyz","method":"POST","headers":{},"bodySchema":{"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)"}}},"responseSchema":null,"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.001","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"probe","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.001/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.001","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.001","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_ftXorPCKbx4lQKlRnRE9D","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.001","costPer":"request","priority":0,"asset":"0xD74f5255D557944cf7Dd0E45FF521520002D5748","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Builds an unsigned close-position transaction for a perpetual futures position on GMX, Hyperliquid, or dYdX, specifying the percentage of the position to close.","exampleAgentPrompt":"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.","exampleUseCases":[{"title":"Partial exit on GMX perps","prompt":"I want to close 50% of my open GMX perpetual position — my position ID is '0xpos456' and my wallet is 0x1234...5678. Can you build that close transaction for me?"},{"title":"Full position exit on Hyperliquid","prompt":"Build me a close transaction to fully exit (100%) my Hyperliquid perpetuals position ID 'hl-99887' for wallet 0xABCD...EF01 — I need the unsigned tx ready to sign."},{"title":"Risk reduction on dYdX perps","prompt":"I'm overleveraged on dYdX — can you build a transaction to close 25% of position 'dydx-pos-7723' for my wallet 0x9999...0000 so I can reduce my risk without fully closing?"}],"resultDescription":"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.","failureModes":["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"],"whenToPreferThis":"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.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-11-14T18:38:04.144Z","isFirstParty":false,"canonicalSlug":"speraxos-build-close-perpetual-position-transaction-f2ed46cc"}