close_perp_position
Closes a Hyperliquid perpetual position fully or partially with a reduce-only market order, reading the side from the live position; rejects flat, oversized, or ambiguous builder-DEX positions.
Instructions
Close (fully or partially) one perp position with a reduce-only market order. The side is read from the live HL position: a long is closed with a sell, a short with a buy. Rejects when the position is flat/missing, when size exceeds it, or when a bare coin is open on several builder DEXes.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dex | No | Builder DEX for a bare coin, e.g. 'xyz' (omit for the default dex) | |
| coin | Yes | Asset symbol to close; builder-DEX assets as 'dex:ASSET', e.g. 'xyz:TSLA' | |
| size | No | Size to close as a decimal string; omit to close the whole position | |
| price | No | Close price; omit or '0' to use the mark price | |
| apiKey | No | GDEX API key for AES encryption | |
| accountRef | No | Connected account from gdex_connect. Supplies session key, wallet address, API key and session data so no secret is passed in chat | |
| szDecimals | No | Market size decimals (HL meta szDecimals); rejects a size with more decimals | |
| walletAddress | No | Control wallet address | |
| positionAddress | No | Address whose HL account holds the position — normally the MANAGED wallet from sign-in. Defaults to walletAddress. | |
| sessionPrivateKey | No | Session private key from sign-in |