--- name: openbroker description: Install, onboard, and operate the OpenBroker Hyperliquid CLI for market and account inspection, restricted API-wallet setup, perp/HIP-3/spot/HIP-4 trading, order management, and TypeScript automations. Use when Codex needs to set up OpenBroker, run or explain `openbroker` commands, inspect Hyperliquid state, safely preview or execute trades, or create and debug OpenBroker automations. --- # OpenBroker — Hyperliquid CLI skill Use the `openbroker` CLI as the canonical interface. Prefer structured JSON output for inspection and dry runs before live writes. ## Operating rules - For unfamiliar assets, **search before trading**. Hyperliquid has main perps, HIP-3 perps, spot markets, and HIP-4 outcomes that can share names. - Prefer `--json` for machine-readable info commands. - Before any write, verify the network, trading account, asset, side, size, open positions/orders, and whether the action should be reduce-only. - Use `--dry` for proposed trades and new or changed trading logic. Execute live only when the user explicitly requests live execution and the dry-run plan matches that intent. - Never infer a live trade size, switch to mainnet, or create/import/export a wallet without explicit user direction. - Never print, echo, log, or expose private keys or seed material. Refer only to the configured signing wallet address when diagnosing identity. - Treat CLI output as exchange state, not just prose: parse order IDs, balances, fills, and errors instead of assuming success. ## First-run installation and API-wallet onboarding Use the following flow when the user asks to install, set up, or use OpenBroker. Do not ask the user for a private key. For a fresh Codex installation, prefer the unified harness installer: ```bash npx --yes openbroker@latest install --codex ``` This installs or updates the Codex skill, installs the persistent `openbroker` CLI, and starts restricted API-wallet onboarding. Keep the command attached while it prints the browser approval link and polls for authorization. If the unified installer is unavailable or the skill is already installed, first check whether Node.js 22+ and the CLI are installed: ```bash node --version command -v openbroker openbroker --version ``` Require OpenBroker 1.9.1 or newer. When the user explicitly asks to set up OpenBroker, install or upgrade the CLI as part of that request, using the normal approval flow for global or network writes: ```bash npm install -g openbroker@latest ``` Public market-data commands such as `search`, `markets`, `funding`, `candles`, and `trades` work without wallet setup. For account-specific reads or trading, prefer a restricted API wallet because it can trade on the user's master Hyperliquid account but cannot withdraw funds. Run setup in an interactive terminal session and select the API-wallet flow directly: ```bash openbroker setup --api-wallet ``` The command generates and stores the API wallet key locally in `~/.openbroker/.env` with mode `0600`, prints an approval URL, and waits up to ten minutes for browser approval. Handle that handoff as follows: 1. Keep the setup process running. Polling output is expected; do not treat it as a stuck command. 2. Capture the `https://openbroker.dev/approve?agent=...` URL from terminal output and immediately show it to the user as a clickable link. 3. Ask the user to open the link, connect the funded master Hyperliquid wallet they want OpenBroker to trade on, review the addresses and network, and sign the requested approvals. On mainnet this authorizes the API agent and the 1 bps builder fee; it does not grant withdrawal access. 4. Never ask the user to paste a master-wallet or API-wallet private key into Codex. Never display the key or read the config file into the conversation. 5. Leave the terminal session running while the user completes approval. The CLI detects approval automatically and saves `HYPERLIQUID_ACCOUNT_ADDRESS` as the master account. 6. After setup completes, verify the connection with `openbroker account --json` and report the master account address, API signing-wallet address, account mode, and equity without exposing secrets. If approval times out, preserve the incomplete config and approval URL. Ask the user to finish approval, then rerun `openbroker setup --api-wallet`; the CLI reuses the existing API key and resumes polling instead of generating another wallet. If a complete config already exists, do not delete or replace it without explicit user approval. Inspect account identity with `openbroker account --json` first. The interactive `openbroker setup` command still supports three modes, with API wallet as the default when the user presses Enter: 1. **Fresh wallet** — creates a separately funded wallet; builder fee approval is handled automatically. 2. **Imported key** — use an existing wallet. 3. **API wallet (default)** — can trade but not withdraw; the human owner approves it in a browser. For API wallets, `HYPERLIQUID_PRIVATE_KEY` is the signing key and `HYPERLIQUID_ACCOUNT_ADDRESS` must be the funded master account. If account output shows `$0` equity unexpectedly, check that mapping first. Common globals: | Flag | Meaning | |---|---| | `-c, --config ` | Use a specific `.env` file | | `--testnet` | Use testnet | | `--dry` | Preview write commands without executing | | `--verbose` | Debug output | | `--json` | Machine-readable output on info commands | ## Asset discovery and IDs ```bash openbroker search --query GOLD --json openbroker search --query BTC --type perp --json openbroker all-markets --type hip3 --json openbroker all-markets --type outcome --json openbroker outcomes --query BTC --json ``` - HIP-3 perps use `dex:COIN`, e.g. `xyz:CL`, not bare `CL`. - `assetId` is the canonical identifier for comparisons and persisted agent state; order placement still uses `--coin`. - For HIP-4 discovery, use `outcomes --json` for grouped market metadata and `all-markets --type outcome --json` for flattened side rows. - HIP-4 outcome orders use `--outcome ` plus `--outcome-side yes|no` when the reference is a plain ID. Encoded sides use `encoding = 10 * outcomeId + side`, where side `0` is the first side and side `1` is the second side. - HIP-4 order books use `#` coins; spot balances may show `+` token names. - On testnet, HIP-3 metadata may need an explicit prefixed coin such as `dex:COIN`. ## CLI command map ### Info commands Most info commands accept `--json`. Use `--coin`, `--top`, and `--address` where the command supports them rather than repeating bespoke parsing logic. | Command | Main use | Distinct flags | |---|---|---| | `account` | Equity, margin, spot balances, positions | `--orders`, `--address` | | `positions` | Open perp positions and liquidation distance | `--coin`, `--address` | | `funding` | Funding rates | `--coin`, `--top`, `--sort annualized|hourly|oi`, `--all`, `--include-hip3` | | `markets` | Perp market data | `--coin`, `--top`, `--sort volume|oi|change`, `--include-hip3` | | `all-markets` | Browse every venue type | `--type perp|hip3|spot|outcome|all`, `--top`, `--json` | | `search` | Find markets across providers | `--query`, `--type` | | `spot` | Spot markets or balances | `--coin`, `--balances`, `--address`, `--top` | | `fills` | Recent fills | `--coin`, `--side buy|sell`, `--top`, `--address` | | `orders` | Order history/open orders | `--coin`, `--status`, `--open`, `--top`, `--address` | | `order-status` | One order by exchange/client ID | `--oid`, `--address` | | `fees` | Fee tier and rates | `--address` | | `candles` | OHLCV | `--coin`, `--interval`, `--bars` | | `funding-history` | Historical funding | `--coin`, `--hours` | | `trades` | Recent tape | `--coin`, `--top` | | `rate-limit` | API usage | — | | `funding-scan` | Cross-dex scan | `--threshold`, `--main-only`, `--hip3-only`, `--pairs`, `--watch`, `--interval`, `--top` | | `outcomes` | HIP-4 discovery/balances | `--query`, `--outcome`, `--side`, `--balances`, `--top`, `--json` | ### Perp trading Shared perp order flags: | Flag | Meaning | |---|---| | `--coin ` | Main perp or HIP-3 `dex:COIN` | | `--side buy|sell` | Required except `buy` / `sell` shortcuts | | `--size ` | Base-asset size | | `--leverage ` | Main perps use cross; HIP-3 uses isolated | | `--reduce` | Reduce-only; use when closing/reducing exposure | | `--slippage ` | Market/SL slippage tolerance | | Command | Shape | |---|---| | `buy`, `sell` | Market shortcuts: `openbroker buy --coin ETH --size 0.1` | | `market` | Explicit market order with `--side` | | `limit` | Add `--price` and optional `--tif GTC|IOC|ALO` | | `trigger` | Add `--trigger`, `--type tp|sl`, optional `--limit` | | `tpsl` | Protect an existing position with `--tp` and/or `--sl`; accepts absolute, `%`, or `entry` forms | | `cancel` | `--all`, `--coin`, or `--oid` | ### Spot and HIP-4 outcome trading | Family | Commands | Shared flags | |---|---|---| | Spot | `spot-buy`, `spot-sell`, `spot-order` | `--coin`, `--side`, `--size`, optional `--price`, `--tif Gtc|Ioc|Alo`, `--slippage` | | Outcomes | `outcome-buy`, `outcome-sell`, `outcome-open`, `outcome-close`, `outcome-order` | `--outcome`, `--outcome-side`, `--side`, `--size`, optional `--price`, `--tif`, `--slippage`, `--sz-decimals` | ### Advanced execution | Command | Use | Distinct flags | |---|---|---| | `twap` | Exchange-managed TWAP | `--duration`, `--randomize`, `--reduce-only` | | `twap-cancel` | Stop a TWAP | `--coin`, `--twap-id` | | `twap-status` | Inspect TWAPs | `--active` | | `scale` | Multi-level ladder | `--levels`, `--range`, `--distribution linear|exponential|flat`, `--tif` | | `bracket` | Entry + linked TP/SL | `--entry market|limit`, `--price`, `--tp`, `--sl`, `--entry-timeout`, `--sl-slippage` | | `chase` | Repriced ALO order | `--offset`, `--timeout`, `--interval`, `--max-chase` | ## High-signal workflows Inspect before trading: ```bash openbroker search --query HYPE --json openbroker account --orders --json openbroker positions --json openbroker markets --coin HYPE --json openbroker buy --coin HYPE --size 1 --dry ``` Close rather than flip: ```bash openbroker positions --coin ETH --json openbroker sell --coin ETH --size 0.1 --reduce --dry ``` For large or passive execution, prefer `limit`, `chase`, `scale`, or `twap` over a blind market order. ## Automations Automations are TypeScript scripts run by the CLI: ```bash openbroker auto run