Hyperliquid SDK

The Hyperliquid SDK is a Python library that allows you to interact with the Hyperliquid protocol. There is the official Python Hyperliquid SDKarrow-up-right which we found quite complex and hard to use. So we decided to build our own SDK, which is more user-friendly and easier to use.

Warning: This is an early version of the library. Use with caution and test thoroughly before trading with real funds. Not all features are available yet.

Repository URL:

Installation & Updates

Using pip:

Using poetry:

⚠️ Note: This library is under active development. We recommend updating regularly to get the latest features and fixes.

Setup

  1. Create a .env file in your project root:

We recommend creating a seperate API key wallet in the Hyperliquid UI for automated trading. This API wallets have not withdrawal permissions.

  1. Initialize the client:

Authentication Modes

The client can operate in three modes:

1. Authenticated with Environment Variables (Default)

2. Authenticated with Explicit Account

3. Unauthenticated Mode

If no credentials are available, the client falls back to unauthenticated mode:

Public vs Private Endpoints

Some methods can be used without authentication:

Methods that require authentication:

The client will automatically warn you when running in unauthenticated mode and help you understand which methods are available.

Basic Usage

Get Market Prices

Check Account Balance

View Positions

Place Orders

Market Buy:

Limit Buy:

Market Sell:

Stop Loss and Take Profit

For Long Positions:

For Short Positions:

The is_buy parameter determines whether the TP/SL order will buy or sell when triggered:

  • For long positions: use is_buy=False (default) to sell when triggered

  • For short positions: use is_buy=True to buy when triggered

Open Position with TP/SL

Alternatively, you can use the convenience methods that handle both entry and TP/SL orders:

Long Position:

Short Position:

These methods automatically set the correct is_buy parameter for TP/SL orders based on the position direction.

Close Position

Cancel Orders

Complete Trading Example

Here's a full example showing a basic trading flow:

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT

Disclaimer

This software is for educational purposes only. Use at your own risk. The authors take no responsibility for any financial losses incurred while using this software.

Last updated