How to Build a Delta-Neutral Bot on Hyperliquid
Build a delta-neutral bot on Hyperliquid: buy spot, short the perp, check the hedge and track funding income. Tested on testnet and both live APIs.

A delta-neutral position is one whose value doesn't move when the price does. The usual Hyperliquid delta neutral strategy is simple: buy a coin on spot, short the same amount on the perp. If the price rises, the spot gains what the short loses, and the other way round. What's left is the funding the short collects every hour while the rate is positive.
Why traders run a delta-neutral position:
• Income without guessing the price. Gains on one leg cancel losses on the other.
• A yield on spare capital. Money that would sit in stablecoins earns the funding instead.
• Less risk than holding the coin. A crash hurts the spot leg and helps the short by the same amount.
Why should you choose to build a delta-neutral bot on Hyperliquid?
The appeal is income that doesn't depend on guessing the price. The work is keeping it that way every hour, which is a bot's job.
• Both legs live in one account. Spot and perp are on the same exchange, through the same API.
• The collateral works together. Under portfolio margin, Hyperliquid's docs say a spot balance offset by a perp short can share collateral, so the two legs' PnL offset each other.
• Funding lands every hour. Your bot sees what the trade earns, and when it stops paying, within the hour.
• It needs constant watching. The legs drift apart, the rate turns negative, the short drifts toward its liquidation price. A bot catches that; a person checking once a day doesn't.
• People already run it. Among the 500 most active traders by 30-day volume, 16 wallets held a perp short covered at least halfway by spot in the same coin, mostly HYPE and BTC. One held an $8.2M HYPE short against 83,542 HYPE on spot. We can't see why each wallet holds it, but the shape is the trade this guide builds.
• Running it for others pays. Your builder code earns a fee on the orders the bot places for its users.
Four steps follow, each tested. To find which markets are worth it in the first place, start with our funding rate arbitrage scanner.
How we tested. Orders went to Hyperliquid's testnet, priced far from the market and canceled straight after. The hedge check and the funding tracker ran against live mainnet data on 31 October 2026, three runs per API. Not a coder? Read the line above each code block and move on. Developers need pip install requests hyperliquid-python-sdk. The examples that read a .txt file expect one full wallet address per line.
This explains how to build the bot. It isn't financial advice.
What "delta neutral" means
Delta is how much a position gains or loses when the price moves. Hold 100 HYPE on spot and short 100 HYPE on the perp, and a $1 move makes $100 on one leg and loses $100 on the other: your delta is zero. What's left is the funding the short collects while the perp trades above spot. On Hyperliquid, that payment arrives every hour.
The same idea goes by other names: a cash-and-carry trade, a basis trade, or funding rate farming.
Step 1: Pick a market with both legs
You need a perp and a spot market for the same coin, both with enough trading to get in and out.
Only 8 perps on Hyperliquid's main DEX had a spot market for the same coin trading more than $1M a day: HYPE, BTC (traded on spot as UBTC), ZEC (UZEC), ETH (UETH), XMR (XMR1, a wrapped XMR), SOL (USOL), PURR and PUMP (UPUMP). That's the realistic list. Wrapped tokens are issued by third parties, so check how each one is backed. HIP-3 markets, where the biggest funding rates usually sit, mostly have no spot leg.
Read the spot pair names from spotMetaAndAssetCtxs, not from a guess: HYPE's main spot pair is @107 on mainnet and @1035 on testnet.
Step 2: Open both legs
The bot buys spot and shorts the perp for the same size. Both orders go to Hyperliquid's /exchange, signed by an API wallet the account owner approves. Orders always go through Hyperliquid; Hydromancer is a data API, built to read market and account data at scale.
We tried sending both legs in one signed request. Hyperliquid rejected it with Order action has different asset classes., so spot and perp have to go as two separate orders:
import os, eth_account
from hyperliquid.exchange import Exchange
from hyperliquid.utils import constants
agent = eth_account.Account.from_key(os.environ["HL_TESTNET_AGENT_KEY"])
ex = Exchange(agent, constants.TESTNET_API_URL,
account_address=os.environ["HL_MAIN_ADDRESS"])
gtc = {"limit": {"tif": "Gtc"}}
spot = ex.order("@1035", True, 0.5, 97.8, gtc) # buy HYPE spot
perp = ex.order("HYPE", False, 0.5, 120.3, gtc) # short HYPE perp
print(spot["response"]["data"], perp["response"]["data"])Both orders rested on testnet, but not at the same moment: sent one after the other, the second leg landed almost a second after the first. Sending both at the same time narrows the gap but doesn't remove it. On mainnet, the price can move in that gap, and one leg can fill while the other doesn't. Your bot needs a rule for that: retry the missing leg, or close the filled one.
Two more things that tripped us up:
• Spot and perp sizes use different decimals. Read szDecimals for each from spotMeta and meta, and round both legs to the coarser one.
• The prices differ on testnet. HYPE was about 85 on the testnet perp and 163 on testnet spot. Testnet is for checking your code, not your pricing.
Step 3: Check the hedge stays balanced
Once both legs are open, the bot keeps checking that spot balance plus perp size is close to zero, and rebalances when it drifts. Drift comes from partial fills, funding and fees paid in the coin, or a user moving funds.
The prototype: check the hedge on a list of accounts and print every short that has spot behind it. We ran it on eight real carry wallets.
Hyperliquid API
Two requests per account: clearinghouseState for the perp and spotClearinghouseState for the spot balance. Spot names can differ from perp names (BTC is held as UBTC), so the prototype checks both:
import requests
URL = "https://api.hyperliquid.xyz/info"
for u in open("carry.txt").read().split():
perp = requests.post(URL, json={"type": "clearinghouseState",
"user": u}).json()
spot = requests.post(URL, json={"type": "spotClearinghouseState",
"user": u}).json()
held = {b["coin"]: float(b["total"]) for b in spot["balances"]}
for p in perp["assetPositions"]:
coin, szi = p["position"]["coin"], float(p["position"]["szi"])
hedge = held.get(coin, held.get("U" + coin, 0)) # UBTC = BTC
if szi < 0 and hedge:
print(u[:10], coin, "short", szi, "spot", round(hedge, 4))Hydromancer API
batchPortfolioStates returns both states for up to 500 accounts in one request. Hydromancer added this endpoint for builder convenience; it isn't part of Hyperliquid's original API, and orders still go through Hyperliquid. Here it is:
import os, requests
H = {"Authorization": "Bearer " + os.environ["HYDROMANCER_API_KEY"]}
users = open("carry.txt").read().split()
r = requests.post("https://api.hydromancer.xyz/info", headers=H,
json={"type": "batchPortfolioStates", "users": users})
for u, st in r.json()["successful_states"]:
held = {b["coin"]: float(b["total"])
for b in st["spotClearinghouseState"]["balances"]}
for p in st["clearinghouseState"]["assetPositions"]:
coin, szi = p["position"]["coin"], float(p["position"]["szi"])
hedge = held.get(coin, held.get("U" + coin, 0)) # UBTC = BTC
if szi < 0 and hedge:
print(u[:10], coin, "short", szi, "spot", round(hedge, 4))Both printed the same 23 shorts with some spot behind them. Several are only lightly covered, which is exactly what this check is for:
0xecb63caa BTC short -222.71694 spot 99.8808
0xecb63caa ETH short -17849.7658 spot 741.2357
0xecb63caa SOL short -175665.59 spot 778.7475
0xecb63caa HYPE short -181771.22 spot 21393.5022
0xecb63caa PUMP short -349376925.0 spot 33729756.3543
0xecb63caa XPL short -22224579.0 spot 1947308.6645
... (17 more lines)Side by side
| Hyperliquid API | Hydromancer API | |
|---|---|---|
| Result | 23 shorts with spot behind them | The same 23 |
| Accounts per request | 1 (two requests each) | Up to 500 |
| Worked | 3 of 3 runs | 3 of 3 runs |
| Time to finish (median) | 2.6 s | 0.2 s |
| Requests | 16 | 1 |
| Rate-limit cost | 32 weight (limit: 1,200 a minute per IP) | 24 points (limit: 20,000 a minute on the Growth plan) |
| Data received over REST (uncompressed) | 0.1 MB | 0.1 MB |
Eight accounts is nothing for either. A bot running the trade for hundreds of users is a different story: at two requests per account, one IP tops out around 300 accounts a minute, or you run your own node with --serve-info.
We used the same request to scan the 500 most active traders: one request returned all 500. That's how we found the 16 carry wallets above. Of those 500 accounts, 244 used the standard mode (the API calls it disabled), 186 a unified account and 38 portfolio margin, while 32 had never picked a mode (default). The mode tells your bot how each account's margin works, so read it with the balances.
Step 4: Track what the trade earns
The point of the trade is the funding. Your bot should show it per hour, net of fees, so users can see when it stops paying.
Hyperliquid API
Each perp position includes cumFunding.sinceOpen. It counts funding paid, so a negative value means the position has received funding: the 8,000 HYPE short in our list read -1532.12, about 1,532 USDC received since it opened. For a payment-by-payment history, userFunding lists the hourly payments, though anything older than about a week comes back merged into daily rows.
Hydromancer API
Its userFunding never merges old payments into daily rows, so you can chart income hour by hour for as long as the trade has run. To report the last hour for all your users in one go, fundingPayments covers every wallet.
Side by side
| Hyperliquid API | Hydromancer API | |
|---|---|---|
| Running total for an open position | cumFunding.sinceOpen, free | Same data in batchPortfolioStates |
| Hour each payment landed | Last week only | Every payment |
| Last hour for 100 users | 137 s, 100 requests | 0.6 s, 1 request |
For your own bot, cumFunding is all you need. Once you report income to many users, hour by hour, the Hydromancer side pays off. The year-long totals comparison is in our funding arbitrage guide.
What can go wrong
• The rate flips. Funding changes every hour. When it turns negative, the short pays instead of earning. Set a rule for when to close.
• The short can still be liquidated. The spot leg hedges price, not margin. Under portfolio margin, Hyperliquid lets spot collateralize the short, but only for HYPE and BTC (with USDC and USDT), the assets it currently accepts. Portfolio margin also has entry requirements (account value over $10,000 or more than $5M weighted volume, and under $25M) and borrowing caps, and falls back to normal margin when those caps are hit.
• Fees eat the first week. Four taker trades in and out cost about a week of funding at the base rate (the math).
• Leverage cuts both ways. A short at 1x needs a huge price jump to liquidate; at 5x, a sharp rally can close it before the spot gain is usable as margin. Run the short at low leverage and keep spare USDC in the perp account.
• The legs don't fill together. See Step 2.
Builder fees on a two-leg trade
Run this trade for other people and your builder code earns on the orders your bot places. Two details are specific to carry bots:
• Three of the four legs pay you. Hyperliquid charges no builder fee on spot buys, so you earn on the perp short, the perp close and the spot sell.
• Keep the builder address separate. It has to be in standard account mode, so it can't be the portfolio-margin account running the trade.
Whatever you charge comes straight out of your user's funding, so keep it low.
Hydromancer's builderApprovedFills and builderApprovedFundings streams follow every fill and funding payment of users who approved your builder fee, so your app can show each user's income as it lands.
Your own account, or a service for others?
For one account, Hyperliquid's free API does everything: two reads per hedge check, cumFunding for income, and the orders themselves. Turn it into a service and the reads multiply by your user count; that's where one batch request and one stream for every user's fills and funding start to matter.
FAQ
What is a delta-neutral strategy on Hyperliquid?
Holding spot and an equal perp short in the same coin, so price moves cancel out and the position collects funding while the rate is positive.
Can I open spot and perp in one order on Hyperliquid?
No. When we sent both in one signed action on testnet, Hyperliquid rejected it with "Order action has different asset classes." Send them as two orders and handle the case where only one fills.
Which coins can I run delta-neutral on Hyperliquid?
You need both a spot and a perp market. When we checked, eight coins with a main-DEX perp had over $1M a day of spot volume: HYPE, BTC, ZEC, ETH, XMR, SOL, PURR and PUMP.
Does portfolio margin help a delta-neutral bot?
Yes, for HYPE and BTC, the coins portfolio margin currently accepts as collateral. Hyperliquid's docs give the carry trade as the example: spot collateralizes the perp short, and spot and perp PnL offset each other. Check the entry requirements and borrow caps first.
How do I know the trade is still worth it?
Track funding received per hour against what the position cost to open and will cost to close. If the rate drops near zero or turns negative, the trade stops paying.
Related reading
• How to build a Hyperliquid funding rate arbitrage tool
• Hyperliquid funding rates: how they work
• How to build a Hyperliquid trading bot
• Hyperliquid testnet guide
• Hyperliquid builder codes
Sources
- Hyperliquid docs: Portfolio margin, Funding, Fees, Builder codes, Exchange endpoint
- Hydromancer docs: batchPortfolioStates, userFunding
Read next

How to Build a Hyperliquid TWAP Execution Tool
Build a TWAP execution tool on Hyperliquid: native TWAP orders vs your own slicing, tracking slice fills, and seeing every active TWAP in a market.

How to Build a Trading Terminal on Hyperliquid
Build a Hyperliquid trading terminal: charts, order book, trades and order entry, plus 1-second candles and older chart history. Tested on both APIs.

How to Build a Trading Journal for Hyperliquid
Build a Hyperliquid trading journal: turn fills into closed trades with entry, exit, fees, funding and hold time, and keep history past 10,000 fills.