df-hyperliquid-coreHyperliquid SDKfor Rust
Markets, trading, transfers, earn, validators and deploys in one crate, with full parity with the Hyperliquid API, exact decimals, and native or wasm transports.
- Full API parity
- All deploys
- Websockets
- HyperEVM
- Wasm builds
- And more
Install it and sign an order.
The example signs a post-only BTC limit buy and its cancel. It prints both signed bodies and sends nothing unless HL_SEND=1 is set.
- Run
- HL_PRIVATE_KEY=0x... cargo run --example signed_order
- Also
- Websocket feeds, a HIP-4 order and a wasm build
- Rust
- 1.94 or later, edition 2024
use std::env;
use std::error::Error;
use df_hyperliquid_core::account::{LocalKey, SignError};
use df_hyperliquid_core::client::native::{Native, clock};
use df_hyperliquid_core::markets::{self, Dex, Precision, perps};
use df_hyperliquid_core::trade::answer::{cancels, orders};
use df_hyperliquid_core::trade::{self, Amount, CancelByCloid, Cloid, L1Action, Market, OrderIntent, Side, Tif};
use df_hyperliquid_core::{Client, Dec, Network};
use zeroize::Zeroizing;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let secret = Zeroizing::new(env::var("HL_PRIVATE_KEY").map_err(|_| "set HL_PRIVATE_KEY to the signing key")?);
let key = LocalKey::from_hex(&secret)?;
let send = env::var("HL_SEND").is_ok_and(|value| value == "1");
let client = Client::new(Native::new(), Network::Mainnet, clock, key);
println!("signer {}", client.signer().address());
let meta = perps::meta(&client, Dex::Main).await?.ok_or("no main dex")?;
let (asset, btc) = meta.find(0, "BTC").ok_or("BTC is not listed")?;
let market = Market::perp(asset, btc.sz_decimals, btc.max_leverage, btc.allows_cross()).ok_or("not a perp")?;
let book = markets::book::l2_book(&client, "BTC", Precision::FULL).await?;
let mid = book.mid().ok_or("the book is empty")?;
// 30% under the mid, worth $12. Alo is refused rather than filled if it would cross.
let price = mid.checked_mul("0.7".parse()?).ok_or("the price overflowed")?;
let notional: Dec = "12".parse()?;
let cloid = Cloid::from_u128(u128::from(clock()));
let intent = OrderIntent::limit(Side::Buy, Amount::Notional(notional), price, Tif::Alo).with_cloid(cloid);
let place = trade::orders::order(&market, &intent, None)?;
let cancel = CancelByCloid::one(market.asset(), cloid);
let order = place.orders().first().ok_or("no order")?;
println!("BTC mid {mid}: buy {} at {}, client id {cloid}", order.size(), order.price());
if !send {
println!("\norder body: {}", signed(&client, &place)?);
println!("\ncancel body: {}", signed(&client, &cancel)?);
println!("\ndry run: nothing was sent. Set HL_SEND=1 to place and cancel the order.");
return Ok(());
}
let placed = client.send(&place).await?;
let answer = orders(&placed, 1)?.into_iter().next().ok_or("no answer for the order")?;
println!("\norder: {answer:?}");
if answer.oid().is_none() {
return Ok(());
}
let cancelled = client.send(&cancel).await?;
println!("cancel: {:?}", cancels(&cancelled, 1)?);
Ok(())
}
/// The body `/exchange` would take for `action`, signed at the client's next nonce.
fn signed(client: &Client<Native, LocalKey>, action: &impl L1Action) -> Result<String, SignError> {
let nonce = client.next_nonce();
let signature = client.signer().sign_digest(&action.digest(nonce, None, client.network()))?;
Ok(action.body(nonce, &signature, None))
}
Full parity, set against the API.
Every info request, exchange action, websocket channel and HyperEVM method the Hyperliquid API docs list is in the crate. Each signed action is checked against @nktkas/hyperliquid and the official Python SDK, and every L1 action on testnet: the node must parse it and recover the signing key. The units of irreversible deploy fields are confirmed against real deploys.
| Area | Status | Module |
|---|---|---|
| Info: perps (meta, contexts, all dexes' metas, funding, predicted funding, open interest caps, active asset data, dex limits and status, categories, annotations, deploy auction) | Supported | markets::perps markets::dexes account::holdings deploy |
| Info: spot (meta, contexts, balances, token details, deploy state, pair deploy auction) | Supported | markets::spot account::holdings deploy |
| Info: HIP-4 outcomes (meta, templates, settled outcomes, deployer limits) | Supported | markets::outcomes |
| Info: market data (mids, L2 book, candles, recent trades) | Supported | markets |
| Info: user state (clearinghouse, open orders, order status, rate limit, role, subaccounts, fees, referral, abstraction, agents, builder fee approval, approved builders) | Supported | account |
| Info: history (fills, fills by time, historical orders, TWAP history and slice fills, funding, ledger, portfolio) | Supported | account::history markets::perps |
| Info: vaults, staking and lending (vault details and equities, delegations, staking summary, history and rewards, validators, borrow and lend states) | Supported | earn |
| Exchange: orders (limit, market, trigger, TP/SL, trailing stop, scale, close) | Supported | trade::orders |
| Exchange: cancel, cancel by cloid, schedule cancel, noop | Supported | trade::manage |
| Exchange: modify, batch modify | Supported | trade::manage |
| Exchange: TWAP order and cancel | Supported | trade::orders |
| Exchange: leverage and isolated margin | Supported | trade::margin |
| Exchange: transfers (usdSend, spotSend, sendAsset, agentSendAsset, usdClassTransfer, subaccount transfers, sendToEvmWithData, HyperCore to HyperEVM) | Supported | transfer account::settings |
| Exchange: withdrawals (withdraw3) and Arbitrum deposits | Supported | transfer |
| Exchange: vaults (vaultTransfer, hip3LiquidatorTransfer) | Supported | earn::vaults |
| Exchange: staking (cDeposit, cDeposit2, cWithdraw, tokenDelegate, claimRewards) | Supported | earn::staking account::settings |
| Exchange: lending (borrowLend) | Supported | earn::lending |
| Exchange: API wallets (approveAgent) | Supported | account::keys |
| Exchange: builder fees (approveBuilderFee) | Supported | account::keys trade::builder |
| Exchange: account settings (userSetAbstraction, agentSetAbstraction, createSubAccount, setReferrer, reserveRequestWeight) | Supported | account::settings |
| Exchange: HIP-4 outcome positions (userOutcome: split, merge, mergeQuestion, negateOutcome) | Supported | trade::outcomes |
| Exchange: multi-sig (multiSig, convertToMultiSigUser) | Supported | utils::sign::multi_sig account::keys |
| Exchange: validator actions (validatorL1Stream, authorizeAqav2Role, CValidatorAction, CSignerAction) | Supported | deploy::aligned earn::validator |
| Deploy: spot tokens (spotDeploy, every sub-action the node accepts, and finalizeEvmContract) | Supported | deploy::spot |
| Deploy: HIP-3 perp dexes (perpDeploy, every sub-action) | Supported | deploy::perp |
| Deploy: HIP-4 outcome markets (outcomeDeploy, activateOutcomeDeployer) | Supported | deploy::outcomes |
| Websocket subscriptions (every channel, including l2, pac and sac) | Supported | live client::native::Feed client::web::Feed |
| Websocket post (info reads and signed actions) | Supported | live::Post Feed::post |
| HyperEVM JSON-RPC (every method the docs list) | Supported | client::evm::rpc |
| HyperCore read precompiles (0x0800 to 0x0814) | Supported | client::evm::precompiles |
| CoreWriter (actions 1 to 17) | Supported | client::evm::corewriter |
- userDexAbstraction and agentEnableDexAbstraction
Deprecated, and mainnet no longer accepts them. userSetAbstraction and agentSetAbstraction replace them.
- HIP-3 star operations
The docs mark them testnet only, and the crate does not target testnet.
- enableAlignedQuoteToken and disableAlignedQuoteToken
The docs list them, but mainnet and testnet refuse both for every shape. The crate keeps them, deprecated, until the node accepts them.
Fastest parsing and secp256k1 signing of the SDKs measured.
Websocket parsing is 2.5 times as fast as hypersdk, the next fastest of seven other SDKs, 2.8 times on books, with a lower p99 and fewer allocations per frame. Fastest signing of the SDKs measured with the optional secp256k1 feature, on the same C library go-hyperliquid uses: 11.3 us against 15.2 us. The pure-Rust default is level with the fastest other Rust SDK: 23.8 us against 24.5 us. Round trips to the venue are about the same for every SDK, because the network takes almost all of the time.
| Measurement | df-hyperliquid-core | Fastest other SDK |
|---|---|---|
| Hash and sign one BTC order, default build, median | 23.8 us | go-hyperliquid 15.2 us |
| Hash and sign one BTC order, secp256k1 feature, median | 11.3 us | go-hyperliquid 15.2 us |
| Websocket parse, recorded frames | 1,181,464 frames/s | hypersdk 481,312 frames/s |
| Websocket parse, l2Book frames | 850,861 frames/s | hypersdk 301,944 frames/s |
| Websocket parse, p99 of one frame | 3.1 us | hypersdk 4.5 us |
| Allocations per frame | 4.7 | hypersdk 7.7 |
| Info round trip (l2Book), median | 345.2 ms | hyperliquid-sdk-rs 313.6 ms |
| Exchange round trip (refused order), median | 375.4 ms | hypersdk 334.7 ms |
Measured on 2026-11-28 on one Apple M5 Max on mains power, from Zurich, against hypersdk, hyperliquid-sdk-rs, quicknode-hyperliquid-sdk, the official Rust and Python SDKs, @nktkas/hyperliquid and go-hyperliquid, all run back to back on the same machine and network; each offline figure is the median of 5 runs. The best figure in each row is marked. The round trips differ by less than the spread between requests, so none is marked.
Used in production.
- tui.hip4.dev
The Hyperliquid terminal: every account, market and protocol call, in one Rust binary
- Atlas
Macro trading and global intelligence platform
- metalliq.xyz
Papertrade and cardboard side by side, hedged with a HIP-3 perp on Hyperliquid
- df-papertrade-core
Rust SDK for papertrade.xyz
- df-elysium-core
Rust SDK for Elysium and its HyperEVM bridge
- hip4-vanity
Searches for an address that scores well against a set of criteria
Common questions.
What is df-hyperliquid-core?
A Rust SDK for Hyperliquid: markets, trading, transfers, earn, validators and deploys (spot, HIP-3 and HIP-4) in one crate, with exact decimals and native or wasm transports. It is free under MIT OR Apache-2.0.
Does it cover the whole Hyperliquid API?
Yes. Every info request, exchange action, websocket channel and HyperEVM method the Hyperliquid API docs list is in the crate. Each signed action is checked byte for byte against @nktkas/hyperliquid and the official Python SDK, and every L1 action on testnet.
Can I build a Hyperliquid front end with it?
Yes. It builds to wasm32 for browsers, Node and Workers, using fetch and WebSocket, so a front end can read markets and sign orders with the same code as a bot. For a branded exchange without building one, perps.studio runs white-label exchanges. perps.studio ↗
How fast is it?
It parses websocket frames faster than the seven other SDKs measured, 2.5 times as fast as hypersdk, the next fastest, with fewer allocations per frame. It has the fastest signing of the SDKs measured with the optional secp256k1 feature, on the same C library go-hyperliquid uses. The pure-Rust default is level with the fastest other Rust SDK. Round trips to the venue are about the same for every SDK, because the network takes almost all of the time.
Which other Hyperliquid SDKs are there?
The official docs list a Python SDK from Hyperliquid, hypersdk for Rust, two community TypeScript SDKs and CCXT. HyperBooks compares them, with the endpoints, explorers and data providers. SDKs and developer tools ↗
Where is the Hyperliquid documentation?
HyperBooks is the complete Hyperliquid documentation from the same author: guides, an FAQ and reference for trading, building and deploying, from HyperCore and the HyperEVM to perps, outcome markets and HYPE. HyperBooks ↗







