Skip to main content

hyperliquid-python

Python SDK (sync and async) for Hyperliquid cryptocurrency exchange with Rest and WS capabilities.

Installation

pip install hyperliquid

Usage

Sync

from hyperliquid import HyperliquidSync

def main():
    instance = HyperliquidSync({})
    ob =  instance.fetch_order_book("BTC/USDC:USDC")
    print(ob)
    #
    # balance = instance.fetch_balance()
    # order = instance.create_order("BTC/USDC:USDC", "limit", "buy", 1, 100000)

main()

Async

import sys
import asyncio
from hyperliquid import HyperliquidAsync

### on Windows, uncomment below:
# if sys.platform == 'win32':
# 	asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

async def main():
    instance = HyperliquidAsync({})
    ob =  await instance.fetch_order_book("BTC/USDC:USDC")
    print(ob)
    #
    # balance = await instance.fetch_balance()
    # order = await instance.create_order("BTC/USDC:USDC", "limit", "buy", 1, 100000)

    # once you are done with the exchange
    await instance.close()

asyncio.run(main())

Websockets

import sys
from hyperliquid import HyperliquidWs

### on Windows, uncomment below:
# if sys.platform == 'win32':
# 	asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

async def main():
    instance = HyperliquidWs({})
    while True:
        ob = await instance.watch_order_book("BTC/USDC:USDC")
        print(ob)
        # orders = await instance.watch_orders("BTC/USDC:USDC")

    # once you are done with the exchange
    await instance.close()

asyncio.run(main())

Raw call

You can also construct custom requests to available "implicit" endpoints

        request = {
            'type': 'candleSnapshot',
            'req': {
                'coin': coin,
                'interval': tf,
                'startTime': since,
                'endTime': until,
            },
        }
        response = await instance.public_post_info(request)

Available methods

REST Unified

  • create_order_request(self, symbol: Str, type: Str, side: Str, amount: str, price: Str = None, params: dict = {})
  • create_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params: dict = {})
  • create_orders_request(self, orders: list, params: dict = {})
  • create_orders(self, orders: list[OrderRequest], params: dict = {})
  • create_sub_account(self, name: str, params: dict = {})
  • create_twap_order(self, symbol: str, side: OrderSide, amount: float, duration: float, params: dict = {})
  • create_vault(self, name: str, description: str, initialUsd: int, params: dict = {})
  • fetch_balance(self, params: dict = {})
  • fetch_canceled_and_closed_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_canceled_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_closed_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_currencies(self, params: dict = {})
  • fetch_deposits(self, code: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_funding_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_funding_rate_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_funding_rate(self, symbol: str, params: dict = {})
  • fetch_funding_rates(self, symbols: Strings = None, params: dict = {})
  • fetch_hip3_markets(self, params: dict = {})
  • fetch_ledger(self, code: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_markets(self, params: dict = {})
  • fetch_my_liquidations(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_ohlcv(self, symbol: str, timeframe: str = '1m', since: Int = None, limit: Int = None, params: dict = {})
  • fetch_open_interest(self, symbol: str, params: dict = {})
  • fetch_open_interests(self, symbols: Strings = None, params: dict = {})
  • fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_order_book(self, symbol: str, limit: Int = None, params: dict = {})
  • fetch_order(self, id: str, symbol: Str = None, params: dict = {})
  • fetch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_position(self, symbol: str, params: dict = {})
  • fetch_positions(self, symbols: Strings = None, params: dict = {})
  • fetch_spot_markets(self, params: dict = {})
  • fetch_status(self, params: dict = {})
  • fetch_swap_markets(self, params: dict = {})
  • fetch_tickers(self, symbols: Strings = None, params: dict = {})
  • fetch_time(self, params: dict = {})
  • fetch_trades(self, symbol: str, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_trading_fee(self, symbol: str, params: dict = {})
  • fetch_withdrawals(self, code: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • action_hash(self, action: object, vaultAddress: Str, nonce: object, expiresAfter: Int = None)
  • add_margin(self, symbol: str, amount: float, params: dict = {})
  • amount_to_precision(self, symbol: Str, amount: object)
  • approve_builder_fee(self, builder: str, maxFeeRate: str)
  • build_approve_builder_fee_sig(self, message: dict)
  • build_send_asset_sig(self, message: dict)
  • build_usd_class_send_sig(self, message: dict)
  • build_usd_send_sig(self, message: dict)
  • build_user_abstraction_sig(self, message: dict)
  • build_user_dex_abstraction_sig(self, message: dict)
  • build_withdraw_sig(self, message: dict)
  • calculate_price_precision(self, price: float, amountPrecision: int, maxDecimals: int)
  • calculate_rate_limiter_cost(self, api: list[str], method: str, path: str, params: object, config: dict = {})
  • cancel_all_orders_after(self, timeout: Int, params: dict = {})
  • cancel_order(self, id: str, symbol: Str = None, params: dict = {})
  • cancel_orders_for_symbols(self, orders: list[CancellationRequest], params: dict = {})
  • cancel_orders_request(self, ids: list[str], symbol: Str = None, params: dict = {})
  • cancel_orders(self, ids: list[str], symbol: Str = None, params: dict = {})
  • cancel_twap_order(self, id: str, symbol: Str = None, params: dict = {})
  • coin_to_market_id(self, coin: Str)
  • construct_phantom_agent(self, hash: object, isTestnet: bool = True)
  • describe(self)
  • edit_order(self, id: str, symbol: str, type: OrderType, side: OrderSide, amount: Num = None, price: Num = None, params: dict = {})
  • edit_orders_request(self, orders: list, params: dict = {})
  • edit_orders(self, orders: list[OrderRequest], params: dict = {})
  • enable_user_dex_abstraction(self, enabled: bool, params: dict = {})
  • extract_type_from_delta(self, data: list[dict] = [])
  • format_vault_address(self, address: Str = None)
  • get_dex_from_hip3_symbol(self, market: Market)
  • get_dex_from_symbols(self, methodName: str, symbols: Strings = None)
  • hash_message(self, message: object)
  • initialize_client(self)
  • is_unified_enabled(self, method: str, address: Str = None, shouldRefresh: bool = False, params: dict = {})
  • market(self, symbol: Str)
  • modify_margin_helper(self, symbol: str, amount: Num, type: str, params: dict = {})
  • nonce(self)
  • price_to_precision(self, symbol: Str, price: object)
  • reduce_margin(self, symbol: str, amount: float, params: dict = {})
  • reserve_request_weight(self, weight: Num, params: dict = {})
  • set_agent_abstraction(self, abstraction: str, params: dict = {})
  • set_leverage(self, leverage: int, symbol: Str = None, params: dict = {})
  • set_margin_mode(self, marginMode: str, symbol: Str = None, params: dict = {})
  • set_ref(self)
  • set_sandbox_mode(self, enabled: bool)
  • set_user_abstraction(self, abstraction: str, params: dict = {})
  • transfer(self, code: str, amount: float, fromAccount: str, toAccount: str, params: dict = {})
  • update_spot_currency_code(self, code: Str)
  • withdraw(self, code: str, amount: float, address: str, params: dict = {})

REST Raw

  • public_post_info(request)
  • private_post_exchange(request)

WS Unified

  • describe(self)
  • create_orders_ws(self, orders: list[OrderRequest], params: dict = {})
  • create_order_ws(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params: dict = {})
  • edit_order_ws(self, id: str, symbol: str, type: str, side: str, amount: Num = None, price: Num = None, params: dict = {})
  • cancel_orders_ws(self, ids: list[str], symbol: Str = None, params: dict = {})
  • cancel_order_ws(self, id: str, symbol: Str = None, params: dict = {})
  • watch_order_book(self, symbol: str, limit: Int = None, params: dict = {})
  • un_watch_order_book(self, symbol: str, params: dict = {})
  • watch_ticker(self, symbol: str, params: dict = {})
  • un_watch_ticker(self, symbol: str, params: dict = {})
  • watch_tickers(self, symbols: Strings = None, params: dict = {})
  • un_watch_tickers(self, symbols: Strings = None, params: dict = {})
  • watch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • watch_my_liquidations(self, symbol: str, since: Int = None, limit: Int = None, params: dict = {})
  • watch_my_liquidations_for_symbols(self, symbols: list[str], since: Int = None, limit: Int = None, params: dict = {})
  • un_watch_my_trades(self, symbol: Str = None, params: dict = {})
  • watch_trades(self, symbol: str, since: Int = None, limit: Int = None, params: dict = {})
  • un_watch_trades(self, symbol: str, params: dict = {})
  • watch_ohlcv(self, symbol: str, timeframe: str = '1m', since: Int = None, limit: Int = None, params: dict = {})
  • un_watch_ohlcv(self, symbol: str, timeframe: str = '1m', params: dict = {})
  • watch_balance(self, params: dict = {})
  • un_watch_balance(self, params: dict = {})
  • watch_positions(self, symbols: Strings = None, since: Int = None, limit: Int = None, params: dict = {})
  • set_positions_cache(self, client: Client, symbols: Strings = None)
  • un_watch_positions(self, symbols: Strings = None, params: dict = {})
  • watch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • un_watch_orders(self, symbol: Str = None, params: dict = {})
  • wait_for_pending_unsubscribe(self, url: str, subHash: str)
  • expire_pending_unsubscribe(self, client: Client, subHash: str, unsubHash: str)
  • wrap_as_post_action(self, request: dict)

Contribution

  • Give us a star ⭐
  • Fork and Clone! Awesome
  • Select existing issues or create a new issue.

Metadata

Release files for hyperliquid 0.4.67

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hyperliquid 0.4.67
File Size Uploaded Provenance Actions
hyperliquid-0.4.67.tar.gz 324.3 kB Without provenance Details for hyperliquid-0.4.67.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hyperliquid 0.4.67
File Interpreter ABI Platform Actions
hyperliquid-0.4.67-py3-none-any.whl Python 3 none any Details for hyperliquid-0.4.67-py3-none-any.whl

Total release size: 686.3 kB

Release files / hyperliquid-0.4.67.tar.gz

Download URL hyperliquid-0.4.67.tar.gz
Size 324.3 kB
Tags Source
SHA-256 checksum
How to use checksums
17e2f32ca6782ca2949e320be005e1b73771aab15b3f5e055b6d47918b2a805b
BLAKE2b-256 checksum
How to use checksums
edc53bffed735aed550691bd41087c2a27fd9abc1abd66b50a7d825f087b135c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Release files / hyperliquid-0.4.67-py3-none-any.whl

Download URL hyperliquid-0.4.67-py3-none-any.whl
Size 362.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f8d9f2f8a2b0c8df9ad2141636b1a4f9e1a7653c3c1dbb571434f82ed8b6d11a
BLAKE2b-256 checksum
How to use checksums
d6663428a7da56bc95a39205b7e65a83794e1c8b019ea450a35ea73aae8a047a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Security for hyperliquid 0.4.67

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page