Hyperliquid Trading Bot in Python

This guide shows how to build a Hyperliquid trading bot in Python with LumiBot, for both AI agent trading and algorithmic trading. LumiBot connects to Hyperliquid through CCXT, the open source library that talks to more than 100 crypto exchanges. You will create a Hyperliquid account and API wallet, connect it, and run two examples: a simple algorithmic trading bot and an agentic trading bot where an AI agent makes the calls.

Hyperliquid at a glance

CCXT exchange id

hyperliquid

Markets

Spot, Perpetual swaps

Testnet (sandbox)

Yes

Credentials

private key, wallet address

Live data streams

prices, order book, trades, candles, your orders, your balance, your positions

CCXT request spacing

about 50 ms between requests

Official site

https://hyperliquid.xyz

API docs

https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api

Fees

https://hyperliquid.gitbook.io/hyperliquid-docs/trading/fees

What is Hyperliquid?

Hyperliquid is a fully onchain, non-custodial exchange that runs on its own blockchain. It offers more than 300 perpetual and spot markets, trading 24/7.

Sign up for Hyperliquid

  1. There is no account form. Open app.hyperliquid.xyz and click Connect, then log in with your email (you get a 6 digit code) or connect an EVM wallet such as Rabby or MetaMask.

  2. If you use a wallet, click Enable Trading and sign the gas-less message. Then click Deposit and add USDC (for example USDC on Arbitrum).

  3. For practice, use the testnet at app.hyperliquid-testnet.xyz. Its faucet (https://app.hyperliquid-testnet.xyz/drip) gives 1,000 mock USDC to addresses that have already deposited on mainnet.

Open a Hyperliquid account

Set up a Hyperliquid API wallet

  1. Hyperliquid has no API key and secret. A bot signs with an API wallet (Hyperliquid’s docs also call it an agent wallet).

  2. Connect your main wallet on app.hyperliquid.xyz and open the API page (https://app.hyperliquid.xyz/API).

  3. Type a name for the API wallet and click Generate. Save the private key it shows right away. It cannot be recovered later.

  4. Click Authorize API Wallet and sign with your main wallet. Pick how long it stays valid (up to 180 days).

  5. Give LumiBot the API wallet private key as privateKey and your main account address (not the API wallet address) as walletAddress.

Which permissions to turn on: There are no permission boxes to set. Hyperliquid says API wallets can act for your account without withdrawal permissions, so the API wallet can trade but cannot withdraw. Keep your main wallet’s private key or seed phrase out of LumiBot.

Warning

A Hyperliquid private key is as powerful as the money it controls. Use a separate wallet or API wallet that holds only what you want the bot to trade, keep the key out of your code and out of Git, and move your funds if the key ever leaks.

Connect Hyperliquid to LumiBot

The simplest way: put these lines in a .env file next to your strategy. LumiBot loads the file, sees TRADING_BROKER=hyperliquid and connects to Hyperliquid for you, so your strategy needs no broker code.

TRADING_BROKER=hyperliquid
HYPERLIQUID_PRIVATE_KEY=your_privateKey
HYPERLIQUID_WALLET_ADDRESS=your_walletAddress
HYPERLIQUID_SANDBOX=true   # testnet; remove this line for your live account

LumiBot reads exactly the fields CCXT needs for Hyperliquid (privateKey, walletAddress). If one is missing, LumiBot stops at start-up and names the variable you still need.

You can also build the broker in code. This is handy when one script talks to more than one exchange, or when you need extra CCXT options. The keys in the config are CCXT’s own credential names for Hyperliquid:

import os

HYPERLIQUID_CONFIG = {
    "exchange_id": "hyperliquid",
    "privateKey": os.environ.get("HYPERLIQUID_PRIVATE_KEY"),
    "walletAddress": os.environ.get("HYPERLIQUID_WALLET_ADDRESS"),
    "sandbox": True,  # testnet first; set False for your live account
}

from lumibot.brokers import Ccxt

broker = Ccxt(HYPERLIQUID_CONFIG)
# then: MyStrategy(broker=broker, ...)

Either way, LumiBot turns on CCXT’s built-in rate limiting for you.

Practice on the Hyperliquid testnet

Hyperliquid has a testnet at https://app.hyperliquid-testnet.xyz with its API at https://api.hyperliquid-testnet.xyz. Authorize a separate API wallet there. Set HYPERLIQUID_SANDBOX=true (or "sandbox": True in a code config) to use it. With email login, Privy gives you a different wallet address on testnet than on mainnet.

CCXT sends sandbox requests to: https://api.hyperliquid-testnet.xyz. Testnet and live accounts use different keys.

Algorithmic trading example: a simple Hyperliquid bot

This bot buys about 50 USDC of BTC on Hyperliquid once and then holds it. It is a starting point to check that your keys, balances and orders work. If the exchange’s minimum order is larger, raise the amount.

from lumibot.entities import Asset
from lumibot.strategies import Strategy


class HyperliquidBuyOnce(Strategy):
    """Buy a small amount of BTC once, then hold it."""

    def initialize(self):
        self.sleeptime = "1H"
        self.set_market("24/7")  # crypto trades all day, every day

    def on_trading_iteration(self):
        coin = Asset("BTC", asset_type=Asset.AssetType.CRYPTO)
        if self.get_position(coin) is not None:
            return  # already holding BTC
        price = self.get_last_price(coin, quote=self.quote_asset)
        if price:
            quantity = round(50 / price, 6)  # about 50 USDC worth
            order = self.create_order(coin, quantity, "buy", quote=self.quote_asset)
            self.submit_order(order)


if __name__ == "__main__":
    # LumiBot reads TRADING_BROKER and the keys from your .env file.
    strategy = HyperliquidBuyOnce(quote_asset=Asset("USDC", asset_type=Asset.AssetType.CRYPTO))
    strategy.run_live()

Agentic trading example: an AI agent that trades on Hyperliquid

Agentic trading means an AI agent reads the market and decides what to do. In this example one LumiBot agent looks at prices and your Hyperliquid account, then places the orders itself. There is no Python logic in between: you set the rules in plain English in the prompt, such as what it may trade and how big each order can be. This follows the same pattern as LumiBot’s AI trading team examples.

from lumibot.entities import Asset
from lumibot.strategies import Strategy


class HyperliquidAITrader(Strategy):
    """One AI agent researches the market and places the trades itself."""

    def initialize(self):
        self.sleeptime = "4H"
        self.set_market("24/7")
        self.agents.create(
            name="trader",
            model="openai/gpt-6-luna",
            reasoning_effort="high",
            allow_trading=True,
            system_prompt=(
                "You manage a small crypto account on Hyperliquid. "
                "You may trade BTC and ETH against USDC (asset_type 'crypto', quote_symbol 'USDC'), or hold cash. "
                "Before every order, call account_portfolio, account_positions and "
                "market_last_price for that exact symbol in the same run. "
                "Keep each order under 10% of the account value. "
                "Explain each decision in one short paragraph."
            ),
        )

    def on_trading_iteration(self):
        self.agents["trader"].run(
            task_prompt="Review recent BTC/USDC and ETH/USDC prices and your current holdings, then decide whether to buy, sell or hold.",
            context={"exchange": "Hyperliquid", "quote": "USDC", "date": self.get_datetime().isoformat()},
        )


if __name__ == "__main__":
    # LumiBot reads TRADING_BROKER and the keys from your .env file.
    strategy = HyperliquidAITrader(quote_asset=Asset("USDC", asset_type=Asset.AssetType.CRYPTO))
    strategy.run_live()

The agent needs a model key such as OPENAI_API_KEY in your environment. See the AI agents quickstart for models, tools and memory.

What you can trade on Hyperliquid through CCXT

Market

Listed by CCXT

Spot

Yes

Margin

No

Perpetual swaps

Yes

Dated futures

No

Options

No

CCXT lists these order features for Hyperliquid: market orders, limit orders, stop orders, reduce-only orders, editing open orders, canceling orders.

For perpetual contracts, use the full CCXT symbol so the settlement currency is clear, for example BTC/USDT:USDT. See the CCXT guide for contract quantities, position modes and leverage.

Hyperliquid tips

  • Account data is looked up by your main account address. Hyperliquid warns that using the API wallet address for queries gives an empty result, so walletAddress must be your main (or sub-account) address.

  • An account can have 1 unnamed and up to 3 named API wallets, plus 2 more named ones per sub-account. Approving a new unnamed API wallet replaces the old one, so give each bot its own named API wallet.

  • API wallets expire on the Valid Until date you chose. When it passes, the bot stops trading until you authorize a new API wallet. Hyperliquid suggests a fresh API wallet each time, not reusing an old address.

  • In CCXT, Hyperliquid perpetuals use symbols like BTC/USDC:USDC and spot uses BTC/USDC.

Frequently asked questions

Can I build a Hyperliquid trading bot in Python?

Yes. Install LumiBot (pip install lumibot), set your Hyperliquid keys and use the hyperliquid CCXT exchange id as shown above.

Does Hyperliquid have a testnet?

Yes. Set HYPERLIQUID_SANDBOX=true and use keys from the Hyperliquid testnet.

Which keys does a Hyperliquid bot need?

There are no permission boxes to set. Hyperliquid says API wallets can act for your account without withdrawal permissions, so the API wallet can trade but cannot withdraw. Keep your main wallet’s private key or seed phrase out of LumiBot.

Can an AI agent trade on Hyperliquid by itself?

Yes. The agentic example above gives one agent permission to trade. You control what it may trade and how much through its prompt.

Can I trade Hyperliquid perpetual futures with LumiBot?

CCXT lists perpetual swaps for this exchange. Use the full contract symbol, such as BTC/USDT:USDT.

Is LumiBot free?

Yes. LumiBot is open source on GitHub at https://github.com/Lumiwealth/lumibot. You pay only your exchange’s trading fees and, for AI agents, your model provider.

Run it in the cloud with BotSpot

Do not want to keep a computer running for your Hyperliquid bot? BotSpot is the hosted home for LumiBot strategies and AI trading agents: build with AI, backtest, connect a broker, and watch every trade with logs and alerts.

Try BotSpot

Sources