@2oolkit/hyperliquid-cli

中文文档
0.2.7发布于 2026/06/23MIT近 30 天下载 2287

CLI & MCP server for Hyperliquid DEX — trade perpetuals & spot, manage orders, and query market data

原始使用文档
文档目录25 节
  1. Installation
  2. Prerequisites
  3. CLI Usage
  4. Quick Start
  5. Configuration
  6. Command Reference
  7. Output Formats
  8. MCP Server
  9. Setup for Claude Code
  10. Setup for Claude Desktop / Cursor / Windsurf
  11. Available Tools (25)
  12. MCP Configuration
  13. OpenClaw Skill
  14. Asset Naming
  15. Common Workflows
  16. Close a Position
  17. Bracket Order (Entry + Take-Profit)
  18. Cancel Everything
  19. Portfolio Health Check
  20. Error Handling
  21. Safety
  22. Configuration Files
  23. Environment Variables
  24. Resources
  25. License

@2oolkit/hyperliquid-cli

Trade perpetuals and spot on Hyperliquid — a high-performance onchain order book DEX — from your terminal or AI agent.

One package, three interfaces:

InterfaceCommandUse Case
CLIhyperliquid-cliTerminal trading, scripting, automation
MCP Serverhyperliquid-mcpAI agents (Claude, Cursor, Windsurf, etc.)
OpenClaw Skillskill/SKILL.mdAI agent ecosystem (OpenClaw, ClawdBot)

200+ perpetual instruments, spot tokens, TWAP orders, and full account management.

Installation

npm install -g @2oolkit/hyperliquid-cli

This installs both hyperliquid-cli (CLI) and hyperliquid-mcp (MCP server).

Prerequisites

  • Node.js >= 20
  • A Hyperliquid wallet with funds deposited
  • Your wallet's private key (for signing transactions)

CLI Usage

Quick Start

# 1. Interactive setup (prompts for environment, private key)
hyperliquid-cli config init

# 2. Check a price (no auth needed)
hyperliquid-cli market ticker BTC

# 3. Place a limit buy
hyperliquid-cli order place -c BTC -s buy -p 60000 -z 0.001

# 4. View open orders
hyperliquid-cli order list

Configuration

Interactive setup (recommended):

hyperliquid-cli config init

Prompts for:

PromptDescription
Environmentmainnet or testnet
Private keyHex private key (input masked with *)

The wallet address is automatically derived from the private key.

Manual setup:

hyperliquid-cli config set --env mainnet --private-key <hex-key>

Environment variables (CI/CD, Docker):

export HYPERLIQUID_WALLET_PRIVATE_KEY=<your-private-key>
export HYPERLIQUID_WALLET_ADDRESS=<your-wallet-address>

View current config:

hyperliquid-cli config list
hyperliquid-cli config get env

Config is saved to ~/.hyperliquid-cli/config.json with 0600 permissions.

Command Reference

Market Data (no auth required)

hyperliquid-cli market meta                        # List all perpetual instruments
hyperliquid-cli market meta --spot                 # List spot instruments
hyperliquid-cli market all-mids                    # All mid prices
hyperliquid-cli market ticker BTC                  # Price, volume, funding, OI
hyperliquid-cli market ticker BTC --spot           # Spot ticker
hyperliquid-cli market orderbook BTC               # L2 order book
hyperliquid-cli market orderbook BTC -d 3          # 3 sig figs depth
hyperliquid-cli market candles BTC -i 1h -n 500    # OHLCV candles (default 500)
hyperliquid-cli market candles BTC -i 1h -n 5000   # Up to 5000 in one request
hyperliquid-cli market candles BTC -i 1h -n 10000 --paginate  # Auto-paginate for more
hyperliquid-cli market funding BTC --hours 24      # Funding rate history
hyperliquid-cli market funding BTC --predicted     # Predicted funding rates
hyperliquid-cli market trades BTC                  # Recent trades

Candles (OHLCV):

The candleSnapshot endpoint returns up to 5000 candles per request (rolling time window, no cursor). The CLI defaults to -n 500.

hyperliquid-cli market candles BTC -i 1h -n 5000 -o json    # Max in a single request
hyperliquid-cli market candles BTC -i 1h -n 10000 --paginate -o json  # Fetch more via auto-pagination
hyperliquid-cli market candles BTC -i 15m --start-time 1700000000000 --end-time 1700864000000 --paginate -o json
OptionDescriptionDefault
-i, --interval <interval>One of 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 8h, 12h, 1d, 3d, 1w, 1M1h
-n, --count <number>Number of candles to fetch500
--paginateAuto-paginate (walk backwards by time) to fetch more than 5000 candlesfalse
--start-time <ms>Window start (Unix ms); overrides the count-based start—
--end-time <ms>Window end (Unix ms)now
  • If -n exceeds 5000 without --paginate, the count is clamped to 5000 with a warning.
  • With --paginate, requests are repeated with endTime = (oldest candle).t − 1ms until the requested count is reached or history is exhausted; results are deduped and sorted ascending by time.

Orders (auth required)

# Place orders
hyperliquid-cli order place -c BTC -s buy -p 60000 -z 0.001              # Limit buy (Gtc)
hyperliquid-cli order place -c BTC -s sell -p 80000 -z 0.001             # Limit sell
hyperliquid-cli order place -c BTC -s buy -p 70000 -z 0.001 --tif Ioc   # Immediate-or-cancel
hyperliquid-cli order place -c BTC -s buy -p 70000 -z 0.001 --tif Alo   # Post-only (add liquidity)
hyperliquid-cli order place -c BTC -s sell -z 0.001 --trigger-px 65000 --tpsl sl  # Stop-loss
hyperliquid-cli order place -c BTC -s sell -z 0.001 --reduce-only -p 80000        # Reduce-only

# Manage orders
hyperliquid-cli order list                                    # Open orders
hyperliquid-cli order get <oid>                               # Order status by ID
hyperliquid-cli order cancel -c BTC --oid <oid>               # Cancel one
hyperliquid-cli order cancel-all                              # Cancel all open orders
hyperliquid-cli order cancel-all -c BTC                       # Cancel all BTC orders only
hyperliquid-cli order modify --oid <oid> -c BTC -s buy -p 61000 -z 0.002  # Modify order

# History
hyperliquid-cli order history                                 # Order history
hyperliquid-cli order fills                                   # Recent fills
hyperliquid-cli order fills --hours 48                        # Fills from last 48h

# TWAP
hyperliquid-cli order twap -c BTC -s buy -z 0.1 -m 30        # TWAP over 30 minutes
hyperliquid-cli order twap-cancel -c BTC --twap-id <id>       # Cancel TWAP

# Dead man switch
hyperliquid-cli order schedule-cancel --delay 60              # Cancel all orders in 60s

Order place options:

OptionRequiredDescriptionDefault
-c, --coin <coin>YesCoin name (e.g., BTC, ETH)—
-s, --side <side>Yesbuy or sell—
-z, --size <size>YesOrder size—
-p, --price <price>YesOrder price—
--tif <tif>NoGtc, Alo (post-only), IocGtc
--reduce-onlyNoReduce onlyfalse
--trigger-px <price>NoTrigger price (stop/TP)—
--tpsl <type>Notp or slsl
--cloid <id>NoClient order ID (128-bit hex)—

Positions

hyperliquid-cli position list                                 # All open positions + margin
hyperliquid-cli position leverage -c BTC -l 10                # Set 10x cross leverage
hyperliquid-cli position leverage -c BTC -l 5 --isolated      # Set 5x isolated
hyperliquid-cli position margin -c BTC -s buy -a 100          # Add $100 isolated margin

Account

hyperliquid-cli account state                     # Clearinghouse state (positions + margin)
hyperliquid-cli account spot                      # Spot token balances
hyperliquid-cli account portfolio                 # Portfolio summary
hyperliquid-cli account fees                      # Fee schedule
hyperliquid-cli account rate-limit                # Rate limit status
hyperliquid-cli account sub-accounts              # Sub-accounts
hyperliquid-cli account referral                  # Referral info
hyperliquid-cli account role                      # User role

Transfers (auth required)

hyperliquid-cli transfer usd-send -d <address> -a 100          # Send USDC on Hyperliquid
hyperliquid-cli transfer spot-send -d <address> -t <token> -a 10  # Send spot token
hyperliquid-cli transfer withdraw -d <address> -a 100           # Withdraw to Arbitrum (~5 min, $1 fee)
hyperliquid-cli transfer spot-to-perp -a 100                    # Spot → Perp
hyperliquid-cli transfer perp-to-spot -a 100                    # Perp → Spot
hyperliquid-cli transfer vault-deposit -v <vault> -a 100        # Vault deposit
hyperliquid-cli transfer vault-withdraw -v <vault> -a 100       # Vault withdraw
hyperliquid-cli transfer approve-agent -a <address>             # Approve API agent

Output Formats

All commands support -o json for scripting and piping:

hyperliquid-cli market ticker BTC -o json
hyperliquid-cli order list -o json | jq '.[].oid'

MCP Server

The MCP (Model Context Protocol) server exposes all Hyperliquid functionality as tools for AI agents. Works with Claude Code, Claude Desktop, Cursor, Windsurf, and any MCP-compatible client.

Setup for Claude Code

claude mcp add hyperliquid-mcp -- hyperliquid-mcp

Setup for Claude Desktop / Cursor / Windsurf

Add to your MCP config file:

{
  "mcpServers": {
    "hyperliquid": {
      "command": "hyperliquid-mcp"
    }
  }
}

Or without global install:

{
  "mcpServers": {
    "hyperliquid": {
      "command": "npx",
      "args": ["-y", "-p", "@2oolkit/hyperliquid-cli", "hyperliquid-mcp"]
    }
  }
}

Available Tools (25)

CategoryToolsAuth
Marketget_all_mids, get_meta, get_ticker, get_orderbook, get_candles, get_funding, get_recent_tradesNo
Ordersplace_order, cancel_order, list_open_orders, get_order_status, get_order_history, get_user_fillsYes
Positionslist_positions, update_leverageYes
Accountget_account_state, get_spot_balances, get_portfolio, get_user_fees, get_rate_limit, get_sub_accountsYes
Transfersusd_send, spot_send, withdraw, usd_class_transferYes

MCP Configuration

Option 1: CLI setup (recommended)

hyperliquid-cli config init

The MCP server reads the same config as the CLI (~/.hyperliquid-cli/).

Option 2: Environment variables in MCP config

Pass credentials directly in your MCP config file — no CLI setup needed:

{
  "mcpServers": {
    "hyperliquid": {
      "command": "hyperliquid-mcp",
      "env": {
        "HYPERLIQUID_WALLET_PRIVATE_KEY": "0x..."
      }
    }
  }
}

OpenClaw Skill

This package includes an OpenClaw skill definition for AI agent ecosystems. The skill file is located at skill/SKILL.md with detailed reference docs in skill/references/.

Compatible with OpenClaw, ClawdBot, and other agent skill platforms.


Asset Naming

Hyperliquid uses short coin names (not trading pairs):

CoinDescription
BTCBitcoin perpetual
ETHEthereum perpetual
SOLSolana perpetual
ARBArbitrum perpetual
DOGEDogecoin perpetual

Use hyperliquid-cli market meta -o json for the full list with size decimals and max leverage.

Spot tokens use the same names. Add --spot flag for spot-specific commands.

Common Workflows

Close a Position

# Long position → sell reduce-only at market
hyperliquid-cli order place -c BTC -s sell -z 0.001 -p 100000 --tif Ioc --reduce-only

# Short position → buy reduce-only at market
hyperliquid-cli order place -c ETH -s buy -z 0.01 -p 1 --tif Ioc --reduce-only

Bracket Order (Entry + Take-Profit)

hyperliquid-cli order place -c BTC -s buy -z 0.01 -p 68000
hyperliquid-cli order place -c BTC -s sell -z 0.01 -p 75000 --reduce-only

Cancel Everything

hyperliquid-cli order cancel-all
hyperliquid-cli position list -o json
# For each position, create opposite reduce-only order

Portfolio Health Check

hyperliquid-cli account state -o json
hyperliquid-cli position list -o json
hyperliquid-cli order list -o json

Error Handling

Errors include actionable recovery instructions:

Error: Private key is not configured.

Try: hyperliquid-cli config init
ErrorRecovery
Private key is not configuredhyperliquid-cli config init
Asset "XXX" not foundCheck with hyperliquid-cli market meta
Invalid leverageUse a valid integer
Exchange API errorCheck the error message for details

Safety

  1. Use --reduce-only for exit orders — prevents accidental position flips
  2. Check instrument specs — hyperliquid-cli market meta -o json for size decimals and max leverage
  3. Start with small sizes when testing
  4. Never expose your private key — config file uses 0600 permissions, key is masked in output
  5. Use testnet first — hyperliquid-cli config set --env testnet

Configuration Files

FilePathDescription
Config~/.hyperliquid-cli/config.jsonEnvironment, private key, wallet address

Config uses 0600 permissions (owner read/write only). Private key is masked when displayed.

Environment Variables

VariableDescription
HYPERLIQUID_WALLET_PRIVATE_KEYPrivate key (overrides config file)
HYPERLIQUID_WALLET_ADDRESSWallet address (overrides config file)
HYPERLIQUID_ENVmainnet or testnet (default: mainnet)

Resources

License

MIT

版本与发布记录

@2oolkit/hyperliquid-cli 共发布 9 个版本,首次发布于 2026/03/15;过去 12 个月发布了 9 个版本。

版本发布日期距今
0.2.7latest2026/06/234 个月前
0.2.62026/03/267 个月前
0.2.52026/03/197 个月前
0.2.42026/03/197 个月前
0.2.32026/03/187 个月前
0.2.22026/03/187 个月前

关于 @2oolkit/hyperliquid-cli 的常见问题

@2oolkit/hyperliquid-cli 是什么?

CLI & MCP server for Hyperliquid DEX — trade perpetuals & spot, manage orders, and query market data

如何安装 @2oolkit/hyperliquid-cli?

在项目目录运行 npm install @2oolkit/hyperliquid-cli,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 hyperliquid-cli、hyperliquid-mcp,可以用 npx hyperliquid-cli 直接运行。

@2oolkit/hyperliquid-cli 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/2oolkit__hyperliquid-cli 是否存在。

@2oolkit/hyperliquid-cli 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@2oolkit/hyperliquid-cli 可以商用吗?

@2oolkit/hyperliquid-cli 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@2oolkit/hyperliquid-cli 的下载量有多少?

根据 npm 官方下载统计,@2oolkit/hyperliquid-cli 在 2026/10/05 – 2026/11/03 这 30 天内被下载 2,287 次,日均约 76 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@2oolkit/hyperliquid-cli 还在维护吗?

最新版本 0.2.7 发布于 2026/06/23(4 个月前);至今共发布 9 个版本,其中过去 12 个月发布了 9 个;首次发布于 2026/03/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。