rhyperliquid
What is rhyperliquid?
rhyperliquid is a production-grade Rust client library for the Hyperliquid decentralized perpetuals exchange. It provides both a programmatic SDK and terminal-based interfaces for traders and developers who demand type-safety, performance, and reliability in their trading infrastructure. rhyperliquid is built with async-first architecture and is licensed under the Apache and MIT licenses.
Design Principles
As a comprehensive Hyperliquid client, rhyperliquid enables developers to build automated trading strategies, analytics tools, and terminal interfaces while maintaining the safety guarantees and performance characteristics that Rust provides. Building a production-ready trading client requires balancing financial precision, cryptographic correctness, and developer experience with practical performance.
More concretely, our principles are:
-
Type Safety & Financial Precision: Every API response, order type, and market data structure is modeled in Rust's type system to catch invalid requests at compile time. We use
rust_decimalfor all financial calculations to eliminate floating-point errors. While network and API errors remain runtime concerns, the library prevents entire classes of invalid requests before they're sent. -
Correctness Over Speed: rhyperliquid prioritizes getting trading operations right. This means proper EIP-712 signing implementation, correct msgpack serialization for action hashing, and careful handling of Hyperliquid's WebSocket heartbeat protocol.
-
Modularity: The crate is structured as composable components. Whether you need just the REST client for backtesting, WebSocket streams for live data, or the CLI for manual trading. All public APIs are documented with examples showing real-world usage patterns.
-
Developer Experience: We believe trading infrastructure should be approachable. The library provides builder patterns for configuration, comprehensive error messages that explain what went wrong, and examples organized by user workflows rather than individual functions. Both library users and CLI users should find the interface intuitive.
-
Battle-Tested Foundations: By leveraging proven crates (tokio for async, reqwest for HTTP, Alloy for Ethereum cryptography), we build on solid foundations rather than reinventing implementations. Our authentication follows Hyperliquid's specifications for both testnet and mainnet environments.
-
Open & Extensible: rhyperliquid is free open source software licensed under Apache/MIT. This enables anyone to build proprietary strategies, modify the client for their needs, or integrate it into larger systems without licensing concerns. We welcome contributions that improve reliability, add features, or enhance documentation.
Features
- Market data queries (spot & perpetuals)
- Account information retrieval
- Order book snapshots
- Historical candle data
- User fills and funding history
- Order placement and cancellation
- Position management
- Vault operations
- Command-line interface for quick queries
Quick Start
Library Usage
use HyperliquidClient;
async
CLI Usage
The CLI provides quick access to market data and account information from your terminal. Below you can find a list of all supported CLI commands. rhyperliquid intentionally only supports place_order and cancel_order (by order id) from the CLI. Other Exchange API commands will be added by request or open source contribution.
# Run CLI commands
# Examples:
# Get all mid prices
# Get all mid prices on testnet
# Get L2 orderbook for BTC
# Get user's open orders (requires HL_PRIVATE_KEY env var)
# Get candle data
# Get vault details
WebSocket Subscriptions
Subscribe to real-time data feeds using the WebSocket interface:
# Subscribe to open orders updates (requires HL_PRIVATE_KEY env var)
RUST_LOG=info
# Subscribe to order book updates
# Subscribe to all mid prices
# Subscribe to trades
WebSocket subscriptions stream live updates until interrupted with Ctrl+C.
CLI Reference
Global Options
| Flag | Description | Default |
|---|---|---|
--network <mainnet|testnet> |
Network to connect to | mainnet |
--allow-signer-key-env |
Allow reading private key from HL_PRIVATE_KEY |
false |
--subscriptions <true|false> |
Enable WebSocket subscription mode | false |
Commands
Exchange API
| Command | Description |
|---|---|
order |
Place an order |
cancel |
Cancel an order by its order id |
Market Data
| Command | Description |
|---|---|
all-mids |
Get mid prices for all assets |
l2-book |
Get L2 orderbook snapshot |
candle-snapshot |
Get historical candle data |
Account & Portfolio
| Command | Description |
|---|---|
open-orders |
Get user's open orders |
frontend-open-orders |
Get frontend-formatted open orders |
user-fills |
Get user's fill history |
user-fills-by-time |
Get fills within time range |
user-rate-limit |
Check user's rate limit status |
order-status |
Get status of specific order |
historical-orders |
Get user's historical orders |
portfolio |
Get user's portfolio |
user-fees |
Get user's fee information |
sub-accounts |
Get user's sub-accounts |
user-role |
Get user's role information |
referral |
Get user's referral information |
Vault Operations
| Command | Description |
|---|---|
vault-details |
Get vault information |
user-vault-equities |
Get user's vault equity |
WebSocket Subscriptions
Market Data Streams
| Command | Description |
|---|---|
subscribe-all-mids |
Stream all mid prices |
subscribe-l2-book |
Stream orderbook updates |
subscribe-candle-snapshot |
Stream candle updates |
subscribe-active-asset-ctx |
Stream active asset context |
subscribe-bbo |
Stream best bid/offer updates |
Account & Trading Streams
| Command | Description |
|---|---|
subscribe-open-orders |
Stream open orders updates |
subscribe-user-events |
Stream user trading events |
subscribe-user-fills |
Stream user fill updates |
subscribe-user-funding |
Stream user funding updates |
subscribe-user-non-funding-ledger-updates |
Stream non-funding ledger updates |
subscribe-active-asset-data |
Stream active asset data for user |
Advanced Streams
| Command | Description |
|---|---|
subscribe-notifications |
Stream user notifications |
subscribe-web-data3 |
Stream web data updates |
subscribe-twap-states |
Stream TWAP order states |
subscribe-clearinghouse-state |
Stream clearinghouse state |
subscribe-user-twap-slice-fills |
Stream TWAP slice fills |
subscribe-user-twap-history |
Stream TWAP order history |
Use --help on any command for detailed parameter information:
Trading Examples
Comprehensive examples demonstrating real trading workflows:
For account transfer examples, see examples/account_transfer.rs.
For position leverage and managing an isolated position see examples/leverage_position.rs.
For advanced order examples see examples/advanced_order.rs.
For TWAP order placement see examples/twap_order.rs.
Installation
As a Library Dependency
Add to your Cargo.toml:
[]
= "0.2"
= { = "1.41", = ["full"] }
CLI Installation
# Install from crates.io
# Or install from source
Building from Source
# Clone the repository
# Build the library
# Build with CLI
# Run tests
# Build documentation
Stability and API Guarantees
This crate is under active development.
- Breaking changes may occur between minor versions (0.1 → 0.2)
- Public API is subject to refinement based on usage feedback
- Testnet testing is strongly recommended before mainnet use
Documentation
Getting Help
If you have questions:
- Check the Hyperliquid API Documentation
- Search existing GitHub Issues
- Open a new Discussion for questions
- Open an Issue for bugs
Requirements
Minimum Supported Rust Version (MSRV)
Rust 1.75.0 or higher is required.
# Verify your Rust version
# Update if needed
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.