Skip to main content

An unofficial client SDK for Hyperliquid

Project description

Unofficial Hyperliquid Python SDK

📚 Documentation | API Reference | Examples

Python 3.11+ License: MIT Code style: ruff

A high-performance, async Python SDK for interacting with the Hyperliquid decentralized exchange.

Features

  • 🚀 Async/await support - Built for high-performance async applications
  • 📊 Complete API coverage - Leverage all available Hyperliquid functionalities
  • 🔄 WebSocket support - Real-time market data and order updates
  • 🛡️ Type-safe - Full type hints and runtime error handling

Installation

Requirements

  • Python 3.11 or higher

Install from PyPI

pip install hl-sdk

Install from source

git clone https://github.com/papicapital/hl-sdk.git
cd hl-sdk
pip install -e .

Quickstart

Basic Usage

import asyncio
from hl import Api
from hl.account import Account

async def main():
    # Initialize with your credentials
    account = Account(
        address="0xYourAddress",
        secret_key="0xYourSecretKey"
    )

    # Create API client
    api = await Api.create(account=account)

    # Get market data
    result = await api.info.perpetual_meta()
    if result.is_ok():
        meta = result.unwrap()
        print(f"Connected to Hyperliquid: {len(meta.universe)} markets available")

    # Get your open orders
    result = await api.info.user_open_orders()
    if result.is_ok():
        orders = result.unwrap()
        print(f"You have {len(orders)} open orders")

if __name__ == "__main__":
    asyncio.run(main())

Environment Variables

For security, store your credentials in environment variables:

export HL_ADDRESS="0xYourAddress"
export HL_SECRET_KEY="0xYourSecretKey"

Then in your code:

import os
from hl.account import Account

account = Account(
    address=os.environ["HL_ADDRESS"],
    secret_key=os.environ["HL_SECRET_KEY"]
)

Place an Order

from hl.types import OrderType, OrderRequest

async def place_limit_order():
    # Create a limit order
    order = OrderRequest(
        asset="BTC",
        is_buy=True,
        size=Decimal("0.001"),  # Size in BTC
        limit_price=Decimal("50000.0"),  # Limit price
        order_type={"limit": {"tif": "Gtc"}},
        reduce_only=False
    )

    # Place the order
    result = await api.exchange.order(order)
    print(f"Order placed: {result.unwrap()}")

WebSocket Subscriptions

from hl.types import L2BookSubscription

async def stream_orderbook():
    # Use WebSocket context manager
    async with api.ws.run():
        # Subscribe to the L2 book for BTC
        sub_id, queue = await api.ws.subscribtions.l2_book(asset="BTC")

        # Process incoming messages
        for _ in range(10):  # Process 10 messages
            msg = await queue.get()
            print(f"Orderbook update: {msg}")

        # Unsubscribe when done
        await api.ws.unsubscribe(sub_id)

Examples

Check out the examples directory for more detailed examples:

Development

Setup Development Environment

# Clone the repository
git clone https://github.com/papicapital/hl-sdk.git
cd hl-sdk

# Install with development dependencies
uv sync --all-groups

# Install pre-commit hooks
uv run pre-commit install

Run Tests

uv run pytest

Type Checking

uv run mypy hl tests

Code Formatting

uv run ruff check --fix
uv run ruff format

Contributing

We welcome contributions! Please see our Contributing Guide for details.

Support

License

This project is licensed under the MIT License - see the LICENSE file for details.

Disclaimer

This is an unofficial SDK and is not affiliated with Hyperliquid. Use at your own risk.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hl_sdk-0.1.0.tar.gz (51.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hl_sdk-0.1.0-py3-none-any.whl (57.1 kB view details)

Uploaded Python 3

File details

Details for the file hl_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: hl_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 51.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.19

File hashes

Hashes for hl_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 954be11bc3b7ca4243b85bb56e99bf8f9719cf49904fca840c9d9e30b3d150e4
MD5 81689e6f769faa1bf18de10ba9ab01da
BLAKE2b-256 1804522448fc082245c6f8d0a332bea31de9903b1bb4f6f887575605302134a7

See more details on using hashes here.

File details

Details for the file hl_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: hl_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 57.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.19

File hashes

Hashes for hl_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 57252300531326d59eb73f5ce264b2562db6038f3ee8fcae126aacf83b3b2a2f
MD5 74814b7105e5df2eb52c7b3c2d9b53e6
BLAKE2b-256 4cb94ff747a34ac0316fb0243d6cba8f999da32d694331518491b2da0da2ebcc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page