hypersdk
A comprehensive Rust SDK for interacting with the Hyperliquid protocol.
Overview
Hyperliquid is a high-performance decentralized exchange with two main components:
- HyperCore: The native L1 chain with perpetual and spot markets
- HyperEVM: An Ethereum-compatible layer for DeFi integrations (Morpho, Uniswap, etc.)
This SDK provides:
- Full HyperCore API support (HTTP and WebSocket)
- Trading operations (orders, cancellations, modifications)
- Real-time market data via WebSocket subscriptions
- Asset transfers between perps, spot, and EVM
- HyperEVM contract interactions (Morpho, Uniswap)
- Type-safe EIP-712 signing for all operations
- Accurate price tick rounding for orders
- HIP-3 support: Query perpetual markets from multiple DEXes
- CLI tool (
hypecli): Command-line interface for Hyperliquid (will be extended in the future)
Installation
Add to your Cargo.toml:
[]
= "0.1"
Quick Start
HyperCore - Query Markets
use hypercore;
async
HyperCore - Place an Order
use ;
use dec;
async
HyperCore - WebSocket Subscriptions
use ;
use StreamExt;
async
HyperEVM - Morpho Lending
use morpho;
async
HyperEVM - Uniswap V3
use uniswap;
async
Examples
There are examples in the examples/ folder. We tried to cover as many cases as possible.
Features
Price Tick Rounding
The SDK includes accurate price tick size calculation for both spot and perpetual markets:
- Perpetual markets: 5 significant figures with max 6 decimal places (6 - sz_decimals)
- Spot markets: 8 decimal places max (8 - sz_decimals) with dynamic tick sizes
The tick size algorithm maintains precision: decimals = clamp(5 - floor(log10(price)) - 1, 0, max_decimals)
use hypercore;
use dec;
let client = mainnet;
let perps = client.perps.await?;
// Get BTC market and round a price
let btc = perps.iter.find.unwrap;
// Round to valid tick size
let rounded = btc.round_price; // Returns 93231
// Directional rounding for order placement
let conservative_ask = btc.round_by_side; // Rounds up to 93232
let aggressive_bid = btc.round_by_side; // Rounds up to 93232
WebSocket Subscriptions
Subscribe to real-time market data:
Transfers support
Transfer assets between three contexts: perpetual balance, spot balance, and HyperEVM.
use ;
use dec;
let client = mainnet;
let signer: PrivateKeySigner = "your_private_key".parse?;
// Transfer between Core and EVM
client.transfer_to_evm.await?;
client.transfer_from_evm.await?;
// Transfer between perps and spot on Core
client.transfer_to_perps.await?;
client.transfer_to_spot.await?;
HIP-3: Multi-DEX Support
The SDK supports HIP-3, allowing you to query and trade HIP-3 perpetual markets:
use hypercore;
let client = mainnet;
// Query all available DEXes
let dexes = client.perp_dexs.await?;
for dex in &dexes
// Get markets from a specific DEX
if let Some = dexes.first
Multi-Sig Support
The SDK supports multi-signature operations for orders and transfers:
use ;
let client = mainnet;
let lead_signer: PrivateKeySigner = "lead_key".parse?;
let signer1: PrivateKeySigner = "key1".parse?;
let signer2: PrivateKeySigner = "key2".parse?;
let multisig_address = "0x...".parse?;
let nonce = now.timestamp_millis as u64;
// Create a multi-sig order
let result = client
.multi_sig
.signer
.signer
.place
.await?;
// Multi-sig transfers
use UsdSend;
let send = UsdSend ;
client
.multi_sig
.signers
.send_usdc
.await?;
// Append pre-existing signatures (useful for offline signature collection)
use Signature;
let existing_sigs: = vec!;
client
.multi_sig
.signatures // Add pre-collected signatures
.signer // Can still add more signers
.place
.await?;
Configuration
Most examples require a private key set via environment variable:
For development, you can use a .env file:
PRIVATE_KEY=your_private_key_here
Documentation
Development
Running Tests
# Run only unit tests
Building Documentation
# Build and open documentation locally
Requirements
- Rust 1.85.0 or higher
- Tokio async runtime
License
This project is licensed under the Mozilla Public License 2.0 - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Disclaimer
This software is provided "as is", without warranty of any kind. Use at your own risk. Trading cryptocurrencies involves substantial risk of loss.
Support
- GitHub Issues: Report bugs or request features
- Documentation: docs.rs/hypersdk
About us
Infinite Field is a high-frequency trading firm. We build ultra-low-latency systems for execution at scale. Performance is everything.
We prioritize practical solutions over theory. If something works and delivers results, that’s what matters. Performance is always the goal, and every piece of code is written with efficiency and longevity in mind.
If you specialize in performance-critical software, understand systems down to the bare metal, and know how to optimize x64 assembly, we’d love to hear from you.
Note: This SDK is not officially affiliated with Hyperliquid. It is a community-maintained project.