Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Trade perpetual futures and spot tokens on Hyperliquid DEX with 18 tools for orders, positions, funding, and USDC transfers.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
SKILL.md
1---2name: hyperliquid3version: 1.4.04description: Trade perpetual futures and spot on Hyperliquid DEX5delivery: script6tools:7- hl_account8- hl_balances9- hl_open_orders10- hl_market11- hl_orderbook12- hl_fills13- hl_candles14- hl_funding15- hl_order16- hl_spot_order17- hl_tpsl_order18- hl_cancel19- hl_cancel_all20- hl_modify21- hl_leverage22- hl_transfer_usd23- hl_withdraw24- hl_deposit25metadata:26starchild:27emoji: "📈"28skillKey: hyperliquid29requires:30env: [WALLET_SERVICE_URL]31user-invocable: true32disable-model-invocation: false33---3435# Hyperliquid Trading3637Trade perpetual futures and spot tokens on Hyperliquid, a fully on-chain decentralized exchange. Orders are signed using this agent's EVM wallet and submitted directly to the Hyperliquid L1.3839## Prerequisites4041Before trading, the wallet policy must be active. Load the **wallet-policy** skill and propose the standard wildcard policy (deny key export + allow `*`). This covers all Hyperliquid operations — USDC deposits, EIP-712 order signing, and withdrawals.4243## Runtime Model: Agent Tools vs Service Scripts (Important)4445Hyperliquid has **two execution modes**. Use the right one for your workflow:4647### 1) Agent tool mode (chat/task runtime)4849Use `hl_*` tools directly in agent conversations and task scripts that run inside the Starchild tool runtime.5051- Best for: human-in-the-loop operations, ad-hoc trades, monitoring flows, orchestration across multiple skills52- Strength: fastest integration with built-in verification workflow (`check → execute → verify`)53- Limitation: `hl_*` tools are tool-runtime capabilities, **not normal Python imports**5455### 2) Service script mode (FastAPI/worker/bot process)5657For standalone services (FastAPI bots, daemons, web backends), call Hyperliquid directly via the bundled client:5859- Use `skills/hyperliquid/client.py` (`HyperliquidClient`)60- This is the recommended path for always-on bots (grid/maker/rebalancer) that should not depend on localhost agent-chat bridging61- `hl_*` tools are not importable as `from ... import hl_order` in plain Python services6263### Service Integration Pattern (recommended)64651. Keep strategy/state machine in your own service process (FastAPI, worker loop, queue consumer)662. Use `HyperliquidClient` for `order`, `cancel`, `open orders`, `fills`, `account`673. Persist bot state locally (orders, fills cursor, grid map, PnL)684. Build admin APIs (`/start`, `/stop`, `/status`, `/history`) around that state6970### Minimal service example (direct client)7172```python73from skills.hyperliquid.client import HyperliquidClient7475client = HyperliquidClient()76address = await client._get_address() # wallet address used for read endpoints7778# Query79account = await client.get_account_state(address)80opens = await client.get_open_orders(address)81fills = await client.get_user_fills(address)8283# Place order (example)84res = await client.place_order(85coin="BTC",86is_buy=True,87size=0.001,88price=95000,89order_type="limit",90)9192# Cancel all BTC orders93await client.cancel_all("BTC")94```9596## Available Tools9798### Account & Market Info99100| Tool | What it does |101|------|--------------|102| `hl_total_balance` | Check how much you can trade with (use this for balance checks!) |103| `hl_account` | See your open positions and PnL |104| `hl_balances` | See your token holdings (USDC, HYPE, etc.) |105| `hl_market` | Get current prices for crypto or stocks |106| `hl_orderbook` | Check order book depth and liquidity |107| `hl_fills` | See recent trade fills and execution prices |108| `hl_candles` | Get price charts (1m, 5m, 1h, 4h, 1d) |109| `hl_funding` | Check funding rates for perps |110| `hl_open_orders` | See pending orders |111112### Trading113114| Tool | What it does |115|------|--------------|116| `hl_order` | Buy or sell perps (crypto/stocks) |117| `hl_spot_order` | Buy or sell spot tokens |118| `hl_tpsl_order` | Place stop loss or take profit orders |119| `hl_leverage` | Set leverage (1x to asset max) |120| `hl_cancel` | Cancel a specific order |121| `hl_cancel_all` | Cancel all open orders |122| `hl_modify` | Change order price or size |123124### Funds125126| Tool | What it does |127|------|--------------|128| `hl_deposit` | Add USDC from Arbitrum (min $5) |129| `hl_withdraw` | Send USDC to Arbitrum (1 USDC fee, ~5 min) |130| `hl_transfer_usd` | Move USDC between spot/perp (rarely needed) |131132---133134## Quick Start135136Just tell the agent what you want to trade - it handles everything automatically.137138**Examples:**139140```141User: "Buy $20 of Bitcoin with 5x leverage"142Agent: [checks balance → sets leverage → places order → reports fill]143Result: "✓ Bought 0.0002 BTC at $95,432 with 5x leverage. Position opened."144145User: "Long NVIDIA with $50, 10x"146Agent: [auto-detects NVIDIA = xyz:NVDA → executes → verifies]147Result: "✓ Bought 0.25 NVDA at $198.50 with 10x leverage. Filled at $198.62."148149User: "Sell my ETH position"150Agent: [checks position size → closes → reports PnL]151Result: "✓ Sold 0.5 ETH at $3,421. Realized PnL: +$12.50"152```153154**You don't need to:**155- Understand account modes or fund transfers156- Check balances manually (agent does it)157- Calculate position sizes (agent does it)158- Verify fills (agent does it)159160**Just say what you want, the agent handles the rest.**161162---163164## Agent Behavior Guidelines165166**🤖 As the agent, you should ALWAYS do these automatically (never ask the user):**1671681. **Check available funds** - Use `hl_total_balance` before EVERY trade to see total available margin1692. **Detect asset type** - Recognize if user wants crypto (BTC, ETH, SOL) or stocks/RWA (NVIDIA→xyz:NVDA, TESLA→xyz:TSLA)1703. **Set leverage** - Always call `hl_leverage` before placing orders (unless user specifies not to)1714. **Verify fills** - After placing ANY order, immediately call `hl_fills` to check if it filled1725. **Report results** - Tell user the outcome: filled price, size, and any PnL1736. **Suggest risk management** - For leveraged positions, remind users about stop losses or offer to set them174175**🎯 User just says:** "buy X" or "sell Y" or "long Z with $N"176177**🔧 You figure out:**178- Current balance (hl_total_balance)179- Asset resolution (crypto vs RWA)180- Leverage settings (hl_leverage)181- Order sizing (calculate from user's $ amount or size)182- Execution (hl_order)183- Verification (hl_fills)184- Final report to user185186**📊 Balance checking hierarchy:**187- ✅ Use `hl_total_balance` - shows ACTUAL available margin regardless of account mode188- ❌ Don't use `hl_account` for balance - may show $0 even if funds available189- ❌ Don't use `hl_balances` for margin - only shows spot tokens190191**🚀 Be proactive, not reactive:**192- Don't wait for user to ask "did it fill?" - check automatically193- Don't ask "should I check your balance?" - just do it194- Don't explain account modes - user doesn't care, just execute195196---197198## Tool Usage Examples199200### Check Account State201202```203hl_account() # Default crypto perps account204hl_account(dex="xyz") # Builder dex (RWA/stock perps) account205```206207Returns `marginSummary` (accountValue, totalMarginUsed, withdrawable) and `assetPositions` array with each position's coin, szi (signed size), entryPx, unrealizedPnl, leverage.208209**Important:** Builder perps (xyz:NVDA, xyz:TSLA, etc.) have separate clearinghouses. Always check the correct dex when trading RWA/stock perps.210211### Check Spot Balances212213```214hl_balances()215```216217Returns balances array with coin, hold, total for USDC and all spot tokens.218219### Check Market Prices220221```222hl_market() # All mid prices223hl_market(coin="BTC") # BTC price + metadata (maxLeverage, szDecimals)224```225226### Side Parameter Convention (read this first)227228All order tools (`hl_order`, `hl_spot_order`, `hl_tpsl_order`, `hl_modify`)229use the same `side` parameter. **Use `"buy"` or `"sell"`** — these are the230documented values and should be your default.231232For safety, the tools also accept these aliases so a model guess doesn't233reverse direction on a leveraged order:234235- Buy family: `"buy"`, `"B"`, `"bid"`, `"long"`, `"L"`, `1`, `true`236- Sell family: `"sell"`, `"S"`, `"A"`, `"ask"`, `"short"`, `0`, `false`237238**An unrecognized value will fail the call with a clear error** — the tool239never defaults to sell (or buy) when `side` is ambiguous. This is intentional:240silently reversing direction on a leveraged position is the worst failure mode.241242Note: Hyperliquid's L1 wire protocol uses `"B"` and `"A"` internally, but the243tool interface here is `buy`/`sell`. Stick to `buy`/`sell` in your calls and244you will never be surprised.245246### Place a Perp Limit Order247248```249hl_order(coin="BTC", side="buy", size=0.01, price=95000)250```251252Places a GTC limit buy for 0.01 BTC at $95,000.253254### Place a Perp Market Order255256```257hl_order(coin="ETH", side="sell", size=0.1)258```259260Omitting `price` submits an IoC order at mid price +/- 3% slippage.261262**Parameter format behavior:**263- Preferred: pass correct JSON types (`size` as number, `reduce_only` as boolean)264- Hyperliquid tools now include tolerant coercion for common LLM formatting mistakes:265- numeric strings like `"0.01"` → `0.01`266- boolean strings like `"true"/"false"` → `true/false`267- integer strings like `"5"`/`"5.0"` → `5`268- Invalid/empty/non-finite values still fail with explicit validation errors269270### Place a Post-Only Order271272```273hl_order(coin="BTC", side="buy", size=0.01, price=94000, order_type="alo")274```275276ALO (Add Liquidity Only) = post-only. Rejected if it would immediately fill.277278**Practical guardrail for bots:** If your ALO price is too close to mid (often within ~0.1% on liquid pairs), Hyperliquid may reject it. For market-making/grid bots, compute current mid first and skip or shift levels that sit inside your no-cross buffer zone.279280### Place a Stop Loss Order281282```283hl_tpsl_order(coin="BTC", side="sell", size=0.01, trigger_px=90000, tpsl="sl")284```285286Automatically sells 0.01 BTC if the price drops to $90,000. Executes as market order when triggered.287288For a limit order when triggered (instead of market):289290```291hl_tpsl_order(coin="BTC", side="sell", size=0.01, trigger_px=90000, tpsl="sl", is_market=false, limit_px=89900)292```293294### Place a Take Profit Order295296```297hl_tpsl_order(coin="ETH", side="sell", size=0.5, trigger_px=3500, tpsl="tp")298```299300Automatically sells 0.5 ETH if the price rises to $3,500. Executes as market order when triggered.301302### Close a Perp Position303304```305hl_order(coin="BTC", side="sell", size=0.01, reduce_only=true)306```307308Use `reduce_only=true` to ensure it only closes, never opens a new position.309310### Place a Spot Order311312```313hl_spot_order(coin="HYPE", side="buy", size=10, price=25.0)314```315316Spot orders use the same interface — just specify the token name.317318### Cancel an Order319320```321hl_cancel(coin="BTC", order_id=12345678)322```323324Get `order_id` from `hl_open_orders`.325326### Cancel All Orders327328```329hl_cancel_all() # Cancel everything330hl_cancel_all(coin="BTC") # Cancel only BTC orders331```332333### Modify an Order334335```336hl_modify(order_id=12345678, coin="BTC", side="buy", size=0.02, price=94500)337```338339### Set Leverage340341```342hl_leverage(coin="BTC", leverage=10) # 10x cross margin343hl_leverage(coin="ETH", leverage=5, cross=false) # 5x isolated margin344```345346### Transfer USDC (rarely needed)347348```349hl_transfer_usd(amount=1000, to_perp=true) # Spot → Perp350hl_transfer_usd(amount=500, to_perp=false) # Perp → Spot351```352353Note: Usually not needed - funds are automatically shared. Only use if you get an error saying you need to transfer.354355### Withdraw USDC to Arbitrum356357```358hl_withdraw(amount=100) # Withdraw to own wallet359hl_withdraw(amount=50, destination="0xABC...") # Withdraw to specific address360```361362Fee: 1 USDC deducted by Hyperliquid. Processing takes ~5 minutes.363364### Deposit USDC from Arbitrum365366```367hl_deposit(amount=500)368```369370Sends USDC from the agent's Arbitrum wallet to the Hyperliquid bridge contract. Minimum deposit: 5 USDC. Requires USDC balance on Arbitrum.371372### Get Candles373374```375hl_candles(coin="BTC", interval="1h", lookback=48)376```377378Intervals: `1m`, `5m`, `15m`, `1h`, `4h`, `1d`. Lookback in hours.379380### Check Funding Rates381382```383hl_funding() # All predicted fundings384hl_funding(coin="BTC") # BTC predicted + 24h history385```386387### Get Recent Fills388389```390hl_fills(limit=10)391```392393---394395## Coin vs RWA Resolution396397When a user asks to trade a ticker, you need to determine whether it's a **native crypto perp** (use plain name) or an **RWA/stock perp** (use `xyz:TICKER` prefix).398399### Decision Workflow4004011. **Known crypto** → use plain name: `"BTC"`, `"ETH"`, `"SOL"`, `"DOGE"`, `"HYPE"`, etc.4022. **Known stock/commodity/forex** → use `xyz:` prefix: `"xyz:NVDA"`, `"xyz:TSLA"`, `"xyz:GOLD"`, etc.4033. **Unsure** → resolve with tool calls:404- First try `hl_market(coin="X")` — if it returns a price, it's a crypto perp405- If not found, try `hl_market(dex="xyz")` to list all RWA markets and search the results406- Use whichever returns a match407408### Common RWA Categories (all use `xyz:` prefix)409410| Category | Examples |411|----------|----------|412| **US Stocks** | `xyz:NVDA`, `xyz:TSLA`, `xyz:AAPL`, `xyz:MSFT`, `xyz:AMZN`, `xyz:GOOG`, `xyz:META`, `xyz:TSM` |413| **Commodities — Metals** | `xyz:GOLD`, `xyz:SILVER`, `xyz:COPPER`, `xyz:PLATINUM`, `xyz:PALLADIUM`, `xyz:ALUMINIUM` |414| **Commodities — Energy** | `xyz:CL` (WTI), `xyz:BRENTOIL`, `xyz:NATGAS`, `xyz:TTF` (EU Gas) |415| **Commodities — Agriculture** | `xyz:CORN`, `xyz:WHEAT` |416| **Commodities — Other** | `xyz:URANIUM` |417| **Indices** | `xyz:SPY` |418| **Forex** | `xyz:EUR`, `xyz:GBP`, `xyz:JPY` |419420> If a user says "buy NVDA" or "trade GOLD", use `xyz:NVDA` / `xyz:GOLD`. These are real-world assets, not crypto.421422### ⚠️ HIP-3 Commodity Price Lookup423424**All 13 commodity markets are HIP-3 builder-deployed perps.** Their symbols use the `xyz:` prefix (e.g. `xyz:GOLD`, `xyz:CL`), NOT standard formats like XAU, XAG, or WTI.425426**Full commodity list:** GOLD, SILVER, COPPER, PLATINUM, PALLADIUM, ALUMINIUM, CL (WTI crude), BRENTOIL, NATGAS, TTF (EU gas), CORN, WHEAT, URANIUM.427428**Key gotcha:** HIP-3 assets are **NOT included in `allMids`** (the standard price feed). This means:429- `hl_market(coin="xyz:GOLD")` may return **no price** or fail to find the asset430- `hl_market(dex="xyz")` lists all builder markets but may not include mid prices431432**The reliable way to get commodity prices is `hl_candles`:**433434```435# Get latest gold price (use 1h candles, lookback=24 for 24h data)436hl_candles(coin="xyz:GOLD", interval="1h", lookback=24)437438# Get latest copper price439hl_candles(coin="xyz:COPPER", interval="1h", lookback=24)440441# Get latest silver price442hl_candles(coin="xyz:SILVER", interval="1h", lookback=24)443```444445The `close` field of the most recent candle = current price. The oldest candle's `open` vs latest `close` gives 24h change.446447### Prefixed Name — Same Tools448449All existing tools work with `xyz:TICKER` — just pass the prefixed coin name:450451```452hl_market(coin="xyz:NVDA") # Check NVIDIA stock perp price453hl_market(dex="xyz") # List ALL available RWA/stock perps454hl_orderbook(coin="xyz:NVDA") # Check liquidity455hl_leverage(coin="xyz:NVDA", leverage=3) # Set leverage (auto-isolated)456hl_order(coin="xyz:NVDA", side="buy", size=0.5, price=188) # Limit buy 0.5 NVDA457hl_order(coin="xyz:TSM", side="buy", size=1) # Market buy 1 TSM458hl_cancel(coin="xyz:NVDA", order_id=12345678) # Cancel order459```460461### Example: User Says "Buy NVIDIA"4624631. Recognize NVIDIA = stock → use `xyz:NVDA`4642. `hl_market(coin="xyz:NVDA")` — Check current price, leverage limits4653. `hl_leverage(coin="xyz:NVDA", leverage=3)` — Set leverage (builder perps use isolated margin)4664. `hl_order(coin="xyz:NVDA", side="buy", size=0.5, price=188)` — Place limit buy4675. `hl_fills()` — Check if filled468469### Notes470471- Builder perps (HIP-3) use isolated margin only — `hl_leverage` handles this automatically472- The `dex` prefix (e.g. `xyz`) identifies which builder deployed the perp473- All tools (candles, orderbook, funding, etc.) work the same way with prefixed names474475---476477## Common Workflows478479### Query Commodity Prices480481User: "What's the gold price?" or "Show me commodity prices" or "Oil price?"482483**Name → Symbol mapping:**484- Metals: GOLD→`xyz:GOLD`, SILVER→`xyz:SILVER`, COPPER→`xyz:COPPER`, PLATINUM→`xyz:PLATINUM`, PALLADIUM→`xyz:PALLADIUM`, ALUMINIUM→`xyz:ALUMINIUM`485- Energy: WTI/Crude Oil→`xyz:CL`, Brent→`xyz:BRENTOIL`, Natural Gas→`xyz:NATGAS`, EU Gas→`xyz:TTF`486- Agriculture: Corn→`xyz:CORN`, Wheat→`xyz:WHEAT`487- Other: Uranium→`xyz:URANIUM`488489**Steps:**4901. Map commodity name → HIP-3 symbol using the table above4912. `hl_candles(coin="xyz:GOLD", interval="1h", lookback=24)` — Get 24h of hourly candles4923. Current price = last candle's `close`4934. 24h change = `(last_close - first_open) / first_open * 100`4945. Repeat for each commodity as needed495496**Do NOT use `hl_market()` for commodities** — HIP-3 assets are not in `allMids`. Always use `hl_candles`.497498**Liquidity note:** CL (WTI) and BRENTOIL have the highest volume. ALUMINIUM, URANIUM, CORN, WHEAT, TTF may have zero or very low liquidity — warn the user before trading these.499500### Trade Crypto Perps (BTC, ETH, SOL, etc.)501502User: "Buy BTC" or "Long ETH with 5x"503504Agent workflow:5051. `hl_total_balance()` → Check available funds5062. `hl_leverage(coin="BTC", leverage=5)` → Set leverage5073. `hl_order(...)` → Place order5084. `hl_fills()` → Verify fill and report result509510### Trade Stocks/RWA (NVIDIA, TESLA, GOLD, etc.)511512User: "Buy NVIDIA" or "Short TESLA"513514Agent workflow:5151. Detect asset type → Convert "NVIDIA" to "xyz:NVDA"5162. `hl_total_balance()` → Check available funds5173. `hl_leverage(coin="xyz:NVDA", leverage=10)` → Set leverage5184. `hl_order(coin="xyz:NVDA", ...)` → Place order5195. `hl_fills()` → Verify fill and report result520521### Close Positions522523User: "Close my BTC position"524525Agent workflow:5261. `hl_account()` → Get current position size5272. `hl_order(coin="BTC", side="sell", size=X, reduce_only=true)` → Close position5283. `hl_fills()` → Report PnL529530### Grid / Market-Making Bot Loop (service mode)531532For always-on bots running inside FastAPI/worker services:5335341. Read open orders via `get_open_orders(address)`5352. Read fills via `get_user_fills(address)`5363. Use **fills as source of truth** for "order executed" events5374. On fill:538- buy fill → place paired sell at next grid level539- sell fill → place paired buy at previous grid level5405. Keep periodic reconciliation: local state vs exchange open orders541542**Important:** Do not treat "order disappeared from open orders" as guaranteed fill. It can also mean cancel/reject/expired. Always confirm with `get_user_fills` (or `get_order_status` when needed).543544### Spot Trading545546User: "Buy 100 HYPE tokens"547548Agent workflow:5491. `hl_total_balance()` → Check available USDC5502. `hl_spot_order(coin="HYPE", side="buy", size=100)` → Buy tokens5513. `hl_balances()` → Verify purchase552553### Deposit/Withdraw Funds554555**Deposit:**556User: "Deposit $500 USDC to Hyperliquid"557Agent: `hl_deposit(amount=500)` → Done558559**Withdraw:**560User: "Withdraw $100 to my Arbitrum wallet"561Agent: `hl_withdraw(amount=100)` → Done (5 min, 1 USDC fee)562563---564565## Order Types566567| Type | Parameter | Behavior |568|------|-----------|----------|569| **Limit (GTC)** | `order_type="limit"` | Rests on book until filled or cancelled |570| **Market (IoC)** | omit `price` | Immediate-or-Cancel at mid +/- 3% slippage |571| **Post-Only (ALO)** | `order_type="alo"` | Rejected if it would cross the spread |572| **Fill-or-Kill** | `order_type="ioc"` + explicit price | Fill immediately at price or cancel |573| **Stop Loss** | `hl_tpsl_order` with `tpsl="sl"` | Triggers when price drops to limit losses |574| **Take Profit** | `hl_tpsl_order` with `tpsl="tp"` | Triggers when price rises to lock gains |575576---577578## Stop Loss & Take Profit Orders579580Stop loss and take profit orders are **trigger orders** that automatically execute when the market reaches a specified price level. Use these to manage risk and lock in profits without monitoring positions 24/7.581582### How They Work5835841. **Order Placement**: Place a dormant trigger order with a trigger price5852. **Monitoring**: Order sits inactive, watching the market price5863. **Trigger**: When market price reaches `trigger_px`, order activates5874. **Execution**: Order executes immediately (as market or limit order)588589### Stop Loss (SL)590591**Use case**: Limit losses on a position by automatically exiting if price moves against you.592593**Example**: You're long BTC at $95,000 and want to exit if it drops below $90,000.594595```596hl_tpsl_order(coin="BTC", side="sell", size=0.1, trigger_px=90000, tpsl="sl")597```598599- **trigger_px=90000**: Activates when BTC drops to $90k600- **side="sell"**: Closes your long position601- **tpsl="sl"**: Marks this as a stop loss order602- **Default**: Executes as market order when triggered (instant exit)603604### Take Profit (TP)605606**Use case**: Lock in gains by automatically exiting when price reaches your profit target.607608**Example**: You're long ETH at $3,000 and want to take profit at $3,500.609610```611hl_tpsl_order(coin="ETH", side="sell", size=1.0, trigger_px=3500, tpsl="tp")612```613614- **trigger_px=3500**: Activates when ETH rises to $3,500615- **side="sell"**: Closes your long position616- **tpsl="tp"**: Marks this as a take profit order617- **Default**: Executes as market order when triggered (instant exit)618619### Market vs Limit Execution620621By default, TP/SL orders execute as **market orders** when triggered (instant fill, possible slippage).622623For more control, use a **limit order** when triggered:624625```626hl_tpsl_order(627coin="BTC",628side="sell",629size=0.1,630trigger_px=90000,631tpsl="sl",632is_market=false,633limit_px=89900634)635```636637- **trigger_px=90000**: Activates at $90k638- **is_market=false**: Use limit order (not market)639- **limit_px=89900**: Limit price when triggered ($89,900)640641**Trade-off**: Limit orders avoid slippage but may not fill in fast-moving markets.642643### Short Positions644645For short positions, reverse the `side` parameter:646647**Stop loss on short** (exit if price rises):648```649hl_tpsl_order(coin="BTC", side="buy", size=0.1, trigger_px=98000, tpsl="sl")650```651652**Take profit on short** (exit if price drops):653```654hl_tpsl_order(coin="BTC", side="buy", size=0.1, trigger_px=92000, tpsl="tp")655```656657### Best Practices6586591. **Always use `reduce_only=true`** (default) - ensures TP/SL only closes positions, never opens new ones6602. **Match size to position** - TP/SL size should equal or be less than your position size6613. **Set both TP and SL** - protect both upside (take profit) and downside (stop loss)6624. **Account for volatility** - don't set stops too tight or they'll trigger on normal price swings6635. **Check open orders** - use `hl_open_orders` to verify TP/SL orders are active664665### Common Mistakes666667| Mistake | Problem | Solution |668|---------|---------|----------|669| Wrong side | SL buys instead of sells | Long position → `side="sell"` for SL/TP |670| Size too large | TP/SL opens new position | Set `size` ≤ position size, use `reduce_only=true` |671| Trigger = limit | Confusion about prices | `trigger_px` = when to activate, `limit_px` = execution price |672| No SL on leverage | Liquidation risk | Always set stop loss on leveraged positions |673674---675676## Perps vs Spot677678| Aspect | Perps | Spot |679|--------|-------|------|680| Tool | `hl_order` | `hl_spot_order` |681| Leverage | Yes (up to asset max) | No |682| Funding | Paid/received every hour | None |683| Short selling | Yes (native) | Must own tokens to sell |684| Check positions | `hl_account` | `hl_balances` |685686---687688## Risk Management689690- **Always check account state before trading** — know your margin usage and existing positions691- **Set leverage explicitly** before opening new positions (default may vary)692- **Use reduce_only** when closing to avoid accidentally opening the opposite direction693- **Monitor funding rates** — high positive funding means longs are expensive to hold694- **Start with small sizes** — Hyperliquid has minimum order sizes per asset (check szDecimals)695- **Post-only (ALO) orders** save on fees (maker vs taker rates)696- **Check fills after market orders** — IoC orders may partially fill or not fill at all697698---699700## Common Errors701702| Error | Fix |703|-------|-----|704| "Unknown perp asset" | Check coin name. Crypto: "BTC", "ETH". Stocks: "xyz:NVDA", "xyz:TSLA" |705| "Insufficient margin" | Use `hl_total_balance` to check funds. Reduce size or add more USDC |706| "Order must have minimum value of $10" | Increase size. Formula: `size × price ≥ $10` |707| "Size too small" | BTC min is typically 0.001. Check asset's szDecimals |708| "Order would cross" | ALO order rejected. Use regular limit order instead |709| "User or wallet does not exist" | Deposit USDC first with `hl_deposit(amount=500)` |710| "Minimum deposit is 5 USDC" | Hyperliquid requires at least $5 per deposit |711| "Policy violation" | Load wallet-policy skill and propose wildcard policy |712| "Action disabled when unified account is active" | Transfers blocked in unified mode (default). Just place orders directly |713| "'side' must be one of: buy/sell ..." | You passed an unrecognized direction. Use `"buy"` or `"sell"`. See **Side Parameter Convention** above |714