Skip to content

BimaPangestu28/hyperliquid-python-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Hyperliquid CLI (hl)

A command-line interface for interacting with the Hyperliquid exchange.

Installation

# Install from source
pip install -e .

# Or install dependencies manually
pip install hyperliquid-python-sdk click eth-account pydantic

Quick Start

# Set your wallet
hl login <private_key>

# Set the network (mainnet or testnet)
hl chain testnet

# Place a buy order
hl buy --asset ETH --size 100

# View positions
hl view open positions

Configuration

Config is stored at ~/.hyperliquid/config.json by default.

Use --config / -c to specify a custom config file:

hl --config /path/to/config.json buy --asset ETH --size 100

Commands

Configuration

# Set wallet
hl login <private_key>

# Set network
hl chain <mainnet|testnet>

# Set defaults
hl set dl <leverage>          # Set leverage (1-100)
hl set da <asset>             # Set default asset
hl set ds <size>              # Set default size
hl set dm <c|i>               # Set margin type (cross/isolated)

Trading

# Buy/Sell
hl buy --asset ETH --size 100 --price @1900 --tp 5% --sl 3%
hl sell --asset ETH --size 50%

# Take Profit / Stop Loss on existing position
hl tp 50% ETH 5%              # TP 50% of ETH position at 5% profit
hl sl 100% BTC 3%             # SL 100% of BTC position at 3% loss

Advanced Strategies

# TWAP (Time-Weighted Average Price)
hl twap buy 1000 ETH 5,10     # Buy $1000 ETH over 10 orders, 5 min apart
hl twap sell 500 SOL 2,5      # Sell $500 SOL over 5 orders, 2 min apart

# Scale Orders
hl scale buy 1000/10 ETH 1800 1900   # 10 buy orders from $1800-$1900
hl scale sell 500/5 BTC 45000 50000  # 5 sell orders from $45k-$50k

# Pair Trading
hl pair buy 1000 BTC/ETH --price 0.05 --tp 0.06 --sl 0.04
hl pair sell 500 SOL/ETH

View Account

hl view upnl                  # Unrealized PNL
hl view wallet balance        # Wallet balance
hl view unfilled orders       # Open orders
hl view open positions        # Open positions

Batch Execution

Execute multiple orders from a JSON file:

hl execute orders.json

Example orders.json:

{
  "orders": [
    {
      "action": "buy",
      "asset": "ETH",
      "size": "100",
      "tp": "5%",
      "sl": "3%"
    },
    {
      "action": "sell",
      "asset": "BTC",
      "size": "50",
      "price": "@45000"
    },
    {
      "action": "twap_buy",
      "asset": "SOL",
      "size": "500",
      "interval": "5,10"
    },
    {
      "action": "scale_buy",
      "asset": "ETH",
      "size": "1000/10",
      "lower": 1800,
      "upper": 1900
    },
    {
      "action": "pair_buy",
      "pair": "BTC/ETH",
      "size": "1000",
      "tp": "0.06",
      "sl": "0.04"
    }
  ]
}

Supported actions: buy, sell, tp, sl, twap_buy, twap_sell, scale_buy, scale_sell, pair_buy, pair_sell

Size Formats

  • 100 or $100 - Absolute USD amount
  • 10% - Percentage of account balance

Price Formats

  • 1900 or @1900 - Limit price
  • Omit for market order (3% slippage)

TP/SL Formats

  • 5% - Percentage from entry
  • +100 or -50 - Absolute dollar change
  • 1900 - Fixed price

Programmatic Usage

from hyperliquid_cli import HyperliquidClient, Config

# Load config
config = Config.load()  # or Config.load("/path/to/config.json")

# Create client
client = HyperliquidClient(config)

# Place orders
import asyncio

async def main():
    result = await client.buy(asset="ETH", size="100", tp="5%", sl="3%")
    print(f"Order: {result.status}")

    positions = client.get_positions()
    for pos in positions:
        print(f"{pos.coin}: {pos.size} @ {pos.entry_price}")

asyncio.run(main())

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages