hyperqit
A Rust SDK for Hyperliquid.
Installation
cargo add hyperqit
Quick Start
Placing Orders
use hyperqit::*;
use alloy::primitives::Address;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let private_key = "your_private_key_here";
let signer = LocalWallet::signer(private_key.to_string());
let user_address = signer.address();
let client = HyperliquidClient::new(
Network::Testnet,
Box::new(signer),
user_address,
);
let order = BulkOrder {
orders: vec![OrderRequest {
asset: 0, is_buy: true,
limit_px: "50000.0".to_string(),
sz: "0.001".to_string(),
reduce_only: false,
order_type: OrderType::Limit(Limit { tif: "Ioc".into() }),
cloid: None,
}],
grouping: "na".to_string(),
};
let result = client.create_position_raw(order).await?;
println!("Order placed: {:?}", result);
Ok(())
}
Multi Sig Operations
use hyperqit::*;
use alloy::primitives::Address;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let primary_signer = LocalWallet::signer("primary_key".to_string());
let primary_address = primary_signer.address();
let other_signers = vec![
Box::new(LocalWallet::signer("signer2_key".to_string())),
Box::new(LocalWallet::signer("signer3_key".to_string())),
];
let client = HyperliquidClient::new(
Network::Testnet,
Box::new(primary_signer),
primary_address,
);
let multi_sig_address: Address = "0x1234...".parse()?;
client.multi_sig_usd_class_transfer(
1000, true, "0xa4b1".to_string(), other_signers, multi_sig_address, ).await?;
println!("Multi-sig transfer completed");
Ok(())
}
Asset IDs & Market Data
Get asset IDs and market information:
use hyperqit::market_info::*;
let perp_info = client.get_perp_info(None).await?;
let spot_info = client.get_spot_info(None).await?;
let unified = create_unified_market_info(perp_info, spot_info);
if let Some(market) = find_market_by_name(&unified, "BTC") {
let btc_perp_id = market.perp.as_ref().map(|p| p.asset_id);
let btc_spot_id = market.spot.as_ref().map(|s| s.asset_id);
println!("BTC Perp ID: {:?}", btc_perp_id);
println!("BTC Spot ID: {:?}", btc_spot_id);
}
let btc_perp_price = get_current_price(&unified, "BTC", true, true); let btc_spot_price = get_current_price(&unified, "BTC", false, true);
Examples
The binary tools demonstrate SDK usage:
dex - DEX operations, order management, and market data
multisig - Multi-signature operations and conversions
transfer - USD transfers between spot and perp accounts
strat - Delta neutral funding rate farming strategy with web interface
deployer - HIP-3 builder-deployed perpetuals deployment and management
Run examples with:
cargo run --bin dex
cargo run --bin multisig
cargo run --bin transfer
cargo run --bin strat
cargo run --bin deployer
Delta Neutral Strategy (strat)
Delta neutral funding rate farming strategy that goes long spot + short perp when funding is positive.
Configuration:
PRIVATE_KEY=your_private_key
USER_ADDRESS=0x1234...
BOT_URL=https://your-webhook-url.com
CHECK_EVERY=60
BIND_ADDR=0.0.0.0:3000
HIP-3 Builder-Deployed Perpetuals (deployer)
The deployer binary demonstrates HIP-3 perpetual deployment using the SDK:
SDK Support:
PerpDeployAction enum for all deployment actions
RegisterAsset - Deploy new perpetual markets
SetOracle - Update oracle and mark prices
SetFundingMultipliers - Configure funding rates
HaltTrading - Control market trading
Example Usage:
let deploy_action = PerpDeployAction::RegisterAsset(RegisterAsset {
max_gas: Some(1000000),
asset_request: RegisterAssetRequest {
coin: "dex:NEWCOIN".to_string(),
sz_decimals: 6,
oracle_px: "100.0".to_string(),
margin_table_id: 0,
only_isolated: false,
},
dex: "dex".to_string(),
schema: Some(PerpDexSchemaInput {
full_name: "New Coin Perpetual".to_string(),
collateral_token: 0,
oracle_updater: None,
}),
});
client.perp_deploy_action(deploy_action).await?;
Signing
The SDK supports multiple signing methods through the Signer trait:
#[async_trait]
pub trait Signer {
async fn sign_order(&self, to_sign: FixedBytes<32>) -> Result<SignedMessage>;
}
Built-in Signers:
LocalWallet - Local private key signing
Extending Signers:
Implement the Signer trait for custom signing backends like hardware wallets, remote signers, or multi-party computation systems.
License
MIT License