DFU
← All products

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.

Coverage
  • Full API parity
  • All deploys
  • Websockets
  • HyperEVM
  • Wasm builds
  • And more
DF-HYPERLIQUID-CORECRATES.IORUST / WASMHYPERLIQUIDYour appmarketsaccounttradetransferearndeployliveclient/info/exchangewebsocketHyperEVM
Get started

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
examples/signed_order.rsView on GitHub ↗
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))
}
What it covers

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.

AreaStatusModule
Info: perps (meta, contexts, all dexes' metas, funding, predicted funding, open interest caps, active asset data, dex limits and status, categories, annotations, deploy auction)Supportedmarkets::perps markets::dexes account::holdings deploy
Info: spot (meta, contexts, balances, token details, deploy state, pair deploy auction)Supportedmarkets::spot account::holdings deploy
Info: HIP-4 outcomes (meta, templates, settled outcomes, deployer limits)Supportedmarkets::outcomes
Info: market data (mids, L2 book, candles, recent trades)Supportedmarkets
Info: user state (clearinghouse, open orders, order status, rate limit, role, subaccounts, fees, referral, abstraction, agents, builder fee approval, approved builders)Supportedaccount
Info: history (fills, fills by time, historical orders, TWAP history and slice fills, funding, ledger, portfolio)Supportedaccount::history markets::perps
Info: vaults, staking and lending (vault details and equities, delegations, staking summary, history and rewards, validators, borrow and lend states)Supportedearn
Exchange: orders (limit, market, trigger, TP/SL, trailing stop, scale, close)Supportedtrade::orders
Exchange: cancel, cancel by cloid, schedule cancel, noopSupportedtrade::manage
Exchange: modify, batch modifySupportedtrade::manage
Exchange: TWAP order and cancelSupportedtrade::orders
Exchange: leverage and isolated marginSupportedtrade::margin
Exchange: transfers (usdSend, spotSend, sendAsset, agentSendAsset, usdClassTransfer, subaccount transfers, sendToEvmWithData, HyperCore to HyperEVM)Supportedtransfer account::settings
Exchange: withdrawals (withdraw3) and Arbitrum depositsSupportedtransfer
Exchange: vaults (vaultTransfer, hip3LiquidatorTransfer)Supportedearn::vaults
Exchange: staking (cDeposit, cDeposit2, cWithdraw, tokenDelegate, claimRewards)Supportedearn::staking account::settings
Exchange: lending (borrowLend)Supportedearn::lending
Exchange: API wallets (approveAgent)Supportedaccount::keys
Exchange: builder fees (approveBuilderFee)Supportedaccount::keys trade::builder
Exchange: account settings (userSetAbstraction, agentSetAbstraction, createSubAccount, setReferrer, reserveRequestWeight)Supportedaccount::settings
Exchange: HIP-4 outcome positions (userOutcome: split, merge, mergeQuestion, negateOutcome)Supportedtrade::outcomes
Exchange: multi-sig (multiSig, convertToMultiSigUser)Supportedutils::sign::multi_sig account::keys
Exchange: validator actions (validatorL1Stream, authorizeAqav2Role, CValidatorAction, CSignerAction)Supporteddeploy::aligned earn::validator
Deploy: spot tokens (spotDeploy, every sub-action the node accepts, and finalizeEvmContract)Supporteddeploy::spot
Deploy: HIP-3 perp dexes (perpDeploy, every sub-action)Supporteddeploy::perp
Deploy: HIP-4 outcome markets (outcomeDeploy, activateOutcomeDeployer)Supporteddeploy::outcomes
Websocket subscriptions (every channel, including l2, pac and sac)Supportedlive client::native::Feed client::web::Feed
Websocket post (info reads and signed actions)Supportedlive::Post Feed::post
HyperEVM JSON-RPC (every method the docs list)Supportedclient::evm::rpc
HyperCore read precompiles (0x0800 to 0x0814)Supportedclient::evm::precompiles
CoreWriter (actions 1 to 17)Supportedclient::evm::corewriter
Not included
  • 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.

Benchmarks

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.

Measurementdf-hyperliquid-coreFastest other SDK
Hash and sign one BTC order, default build, median23.8 usgo-hyperliquid 15.2 us
Hash and sign one BTC order, secp256k1 feature, median11.3 usgo-hyperliquid 15.2 us
Websocket parse, recorded frames1,181,464 frames/shypersdk 481,312 frames/s
Websocket parse, l2Book frames850,861 frames/shypersdk 301,944 frames/s
Websocket parse, p99 of one frame3.1 ushypersdk 4.5 us
Allocations per frame4.7hypersdk 7.7
Info round trip (l2Book), median345.2 mshyperliquid-sdk-rs 313.6 ms
Exchange round trip (refused order), median375.4 mshypersdk 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

Used in production.

Apps
  • 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

Crates built on it
Questions

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 ↗

See related