Trading API & SDK · SDK Setup & Authentication · 1/8
Python SDK Installation
Overview
The hyperliquid-python-sdk is the official Python SDK for interacting with the Hyperliquid exchange (source). It wraps the HTTP API (POST /info for reads, POST /exchange for signed actions) and the WebSocket feed, handling request signing and nonces for you. Code in this course matches SDK v0.24.0 (October 2026), which requires Python 3.9 or newer.
Installation
pip install hyperliquid-python-sdk
Or with a virtual environment (recommended):
python -m venv venv
source venv/bin/activate # Linux/Mac
pip install hyperliquid-python-sdk
Core Classes
The SDK is built around two classes, Info and Exchange; WebSocket streaming is reached through Info:
1. Info — Read-Only Data
from hyperliquid.info import Info
from hyperliquid.utils import constants
info = Info(base_url=constants.MAINNET_API_URL, skip_ws=True) # skip_ws=True: REST only
The Info class provides read-only access to:
- Market data (prices, order books, candles)
- Account data (balances, positions, open orders)
- Funding rates and oracle prices
- Historical trades and fills
2. Exchange — Trading Operations
import os
import eth_account
from hyperliquid.exchange import Exchange
from hyperliquid.utils import constants
wallet = eth_account.Account.from_key(os.environ["HL_PRIVATE_KEY"]) # never hardcode keys
exchange = Exchange(wallet, base_url=constants.TESTNET_API_URL) # testnet while learning
The Exchange class handles authenticated operations:
- Placing and cancelling orders
- Modifying orders
- Setting leverage
- Transferring funds
3. WebSocket — Real-Time Data
There is no separate WebSocket class. Unless you pass skip_ws=True, Info opens a connection to wss://api.hyperliquid.xyz/ws (derived from base_url) and you subscribe with callbacks:
from hyperliquid.info import Info
from hyperliquid.utils import constants
info = Info(base_url=constants.MAINNET_API_URL)
info.subscribe({"type": "allMids"}, print)
Testnet vs Mainnet
Always develop on testnet first:
| Environment | API URL | WebSocket URL |
|---|---|---|
| Mainnet | https://api.hyperliquid.xyz | wss://api.hyperliquid.xyz/ws |
| Testnet | https://api.hyperliquid-testnet.xyz | wss://api.hyperliquid-testnet.xyz/ws |
Authentication
Hyperliquid uses Ethereum-style signatures instead of exchange-issued API keys. Every /exchange request is signed by a private key. This means:
- You control your own keys
- Reads (
/info) need no signature at all - For bots, the recommended setup is an API wallet (also called an agent wallet): a separate key that your main account approves to sign on its behalf. Pass your main account's address as
account_addresswhen you createExchangewith the API wallet key, and always query account data with the main address, not the API wallet's (docs)
import eth_account
# From private key
wallet = eth_account.Account.from_key("0x...")
# Your address
print(wallet.address) # 0x...
Security Note: Never hardcode private keys. Use environment variables or a secrets manager.