Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (hyperliquid-cli) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Hyperliquid CLI
A command-line interface for Hyperliquid DEX built with the @nktkas/hyperliquid TypeScript SDK.
Installation
# Clone and install
git clone <repo-url>
cd hyperliquid-cli
pnpm install
# Build and link globally
pnpm build
pnpm link --global
# Now 'hl' command is available globally
hl --helpConfiguration
Environment Variables
# Required for trading commands
export HYPERLIQUID_PRIVATE_KEY=0x...
# Optional: explicitly set wallet address (derived from key if not provided)
export HYPERLIQUID_WALLET_ADDRESS=0x...Global Options
| Option | Description |
|---|---|
--json |
Output in JSON format |
--testnet |
Use testnet instead of mainnet |
-V, --version |
Show version number |
-h, --help |
Show help |
Commands
Info Commands (Read-only, no authentication required)
Get Prices
# All assets
hl info prices
# Specific asset
hl info prices --pair BTC
# JSON output
hl info prices --pair ETH --jsonGet Asset Metadata
hl info meta
hl info allPerpMetasGet Full Market Data
# Includes prices, funding rates, open interest
hl info marketsGet Order Book
hl info book BTC
hl info book ETH --jsonGet Account Positions
# Using configured wallet
hl info positions
# Using specific address
hl info positions --user 0x...Get Open Orders
# Using configured wallet
hl info orders
# Using specific address
hl info orders --user 0x...Trade Commands (Requires authentication)
Place Orders
Limit Order (default):
hl trade order BTC buy 0.001 50000
hl trade order ETH sell 0.1 3500 --tif Gtc
hl trade order SOL buy 1 100 --reduce-onlyMarket Order:
hl trade order BTC buy 0.001 --type market
hl trade order ETH sell 0.1 --type market --slippage 0.5Stop-Loss Order:
hl trade order BTC sell 0.001 48000 --type stop-loss --trigger 49000
hl trade order BTC sell 0.001 48000 --type stop-loss --trigger 49000 --tpslTake-Profit Order:
hl trade order BTC sell 0.001 55000 --type take-profit --trigger 54000
hl trade order BTC sell 0.001 55000 --type take-profit --trigger 54000 --tpslOrder Options:
| Option | Description |
|---|---|
--type <type> |
Order type: limit (default), market, stop-loss, take-profit |
--tif <tif> |
Time-in-force: Gtc (default), Ioc, Alo |
--reduce-only |
Reduce-only order |
--slippage <pct> |
Slippage percentage for market orders (default: 1%) |
--trigger <price> |
Trigger price for stop-loss/take-profit orders |
--tpsl |
Mark as TP/SL order for position management |
Cancel Orders
hl trade cancel BTC 12345Set Leverage
# Cross margin (default)
hl trade leverage BTC 10
# Isolated margin
hl trade leverage BTC 10 --isolated
# Explicit cross margin
hl trade leverage ETH 5 --crossReferral Commands
Set Referral Code
hl referral set MYCODEGet Referral Status
hl referral statusExamples
Testnet Trading
# Set testnet private key
export HYPERLIQUID_PRIVATE_KEY=0x...
# Check positions on testnet
hl --testnet info positions
# Place a testnet order
hl --testnet trade order BTC buy 0.001 50000Scripting with JSON Output
# Get BTC price
BTC_PRICE=$(hl info prices --pair BTC --json | jq -r '.price')
echo "BTC: $BTC_PRICE"
# Get all positions as JSON
hl info positions --json | jq '.positions[] | {coin, size, pnl: .unrealizedPnl}'
# Check open orders
hl info orders --json | jq '.[] | select(.coin == "BTC")'Automated Trading
#!/bin/bash
# Simple limit order script
COIN="BTC"
SIDE="buy"
SIZE="0.001"
PRICE="85000"
echo "Placing $SIDE order for $SIZE $COIN @ $PRICE"
hl trade order $COIN $SIDE $SIZE $PRICE --jsonDevelopment
# Run without building
pnpm dev -- info prices
# Type check
pnpm typecheck
# Build
pnpm buildProject Structure
hyperliquid-cli/
├── package.json
├── tsconfig.json
├── .env.example
├── src/
│ ├── index.ts # Entry point
│ ├── cli/
│ │ ├── program.ts # Commander program setup
│ │ ├── context.ts # CLI context (clients, config)
│ │ └── output.ts # Output formatting (JSON/text)
│ ├── commands/
│ │ ├── index.ts # Command registration
│ │ ├── referral.ts # referral set/status
│ │ ├── info.ts # prices, meta, markets, positions, orders, book
│ │ └── trade.ts # order, cancel, leverage
│ └── lib/
│ ├── config.ts # Environment config
│ └── validation.ts # Input validationLicense
MIT