SDK Reference
Python SDK
The official Hyperliquid Python SDK provides a high-level interface for both the Info API (market data, no auth) and the Exchange API (trading, requires signing).
Installation
pip
pip install hyperliquid-python-sdk
Read Market Data (Info API)
The Info client requires no private key.
Fetch prices and metadata
from hyperliquid.info import Info
from hyperliquid.utils import constants
# Testnet
info = Info(constants.TESTNET_API_URL, skip_ws=True)
# Mainnet
# info = Info(constants.MAINNET_API_URL, skip_ws=True)
# All current mid prices
mids = info.all_mids()
print(f"HYPE price: {mids['HYPE']}")
# Perpetuals metadata (asset names, sz_decimals, max_leverage)
meta = info.meta()
for asset in meta["universe"]:
print(asset["name"], asset["szDecimals"])User account state
address = "0xYourAddress"
state = info.user_state(address)
print("Account value:", state["crossMarginSummary"]["accountValue"])
print("Open positions:", state["assetPositions"])Funding rate history
import time
funding = info.funding_history(
coin="HYPE",
start_time=int((time.time() - 7 * 24 * 3600) * 1000), # 7 days ago in ms
)
for entry in funding:
print(entry["time"], entry["fundingRate"])Place Orders (Exchange API)
Never hardcode private keys. Use environment variables or a secrets manager. Consider using an API wallet (agent key) to limit permissions.
Initialize Exchange client
import eth_account from hyperliquid.exchange import Exchange from hyperliquid.utils import constants private_key = "0xYOUR_PRIVATE_KEY" # Use env var in production account = eth_account.Account.from_key(private_key) exchange = Exchange(account, constants.TESTNET_API_URL)
Place a GTC limit order
# Buy 0.1 HYPE at $25.00 (GTC = Good Til Canceled)
result = exchange.order(
name="HYPE",
is_buy=True,
sz=0.1,
limit_px=25.0,
order_type={"limit": {"tif": "Gtc"}},
reduce_only=False,
)
print(result)Market order (IOC)
# IOC = Immediate or Cancel (fills at market, cancels remainder)
result = exchange.order(
name="HYPE",
is_buy=True,
sz=0.1,
limit_px=999999, # High price for buy market
order_type={"limit": {"tif": "Ioc"}},
reduce_only=False,
)Cancel an order
# Cancel by asset + order ID
exchange.cancel("HYPE", oid=123456789)Update leverage
# Set 5x cross margin leverage on HYPE exchange.update_leverage(5, "HYPE", is_cross=True)
Precision & Rounding
Hyperliquid is strict about decimal precision. Always round sizes and prices using szDecimals from the meta endpoint to avoid "Invalid order" errors.
Correct rounding helper
def round_to_sz_decimals(value: float, sz_decimals: int) -> float:
return round(value, sz_decimals)
def round_to_px_decimals(value: float, px_decimals: int) -> float:
# px_decimals is typically 5 significant figures
from decimal import Decimal
d = Decimal(str(value))
return float(d.quantize(Decimal('0.' + '0' * px_decimals)))
# Example: HYPE has szDecimals = 2
sz = round_to_sz_decimals(0.123456, sz_decimals=2) # → 0.12Transfers & Withdrawals
Transfer USDC to another user (internal, instant)
exchange.usd_send(
destination="0xRecipientAddress",
amount=100.0,
)Withdraw USDC via bridge (~5 min, $1 fee)
exchange.withdraw3(
destination="0xYourL1Address",
amount=100.0,
)Full examples and changelog: github.com/hyperliquid-dex/hyperliquid-python-sdk