Crates.io | hyperqit |
lib.rs | hyperqit |
version | 0.1.7 |
created_at | 2025-08-20 13:32:19.144867+00 |
updated_at | 2025-09-05 13:36:39.587682+00 |
description | rust sdk for interacting with hyperliquid |
homepage | |
repository | |
max_upload_size | |
id | 1803409 |
size | 296,040 |
A Rust SDK for Hyperliquid.
cargo add hyperqit
use hyperqit::*;
use alloy::primitives::Address;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Setup signer
let private_key = "your_private_key_here";
let signer = LocalWallet::signer(private_key.to_string());
let user_address = signer.address();
// Create client
let client = HyperliquidClient::new(
Network::Testnet,
Box::new(signer),
user_address,
);
// Place an order
let order = BulkOrder {
orders: vec![OrderRequest {
asset: 0, // BTC perpetual
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(())
}
use hyperqit::*;
use alloy::primitives::Address;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Setup primary signer
let primary_signer = LocalWallet::signer("primary_key".to_string());
let primary_address = primary_signer.address();
// Setup other signers
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,
);
// Multi-sig USD transfer
let multi_sig_address: Address = "0x1234...".parse()?;
client.multi_sig_usd_class_transfer(
1000, // amount
true, // to_perp
"0xa4b1".to_string(), // chain ID
other_signers, // other signers
multi_sig_address, // multi-sig address
).await?;
println!("Multi-sig transfer completed");
Ok(())
}
Get asset IDs and market information:
use hyperqit::market_info::*;
// Get unified market data
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);
// Find asset by name and get ID
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);
}
// Get current prices
let btc_perp_price = get_current_price(&unified, "BTC", true, true); // perp, use_mid
let btc_spot_price = get_current_price(&unified, "BTC", false, true); // spot, use_mid
The binary tools demonstrate SDK usage:
dex
- DEX operations, order management, and market datamultisig
- Multi-signature operations and conversionstransfer
- USD transfers between spot and perp accountsstrat
- Delta neutral funding rate farming strategy with web interfacedeployer
- HIP-3 builder-deployed perpetuals deployment and managementRun examples with:
cargo run --bin dex
cargo run --bin multisig
cargo run --bin transfer
cargo run --bin strat
cargo run --bin deployer
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
deployer
)The deployer
binary demonstrates HIP-3 perpetual deployment using the SDK:
SDK Support:
PerpDeployAction
enum for all deployment actionsRegisterAsset
- Deploy new perpetual marketsSetOracle
- Update oracle and mark pricesSetFundingMultipliers
- Configure funding ratesHaltTrading
- Control market tradingExample Usage:
// Deploy new perpetual market
let deploy_action = PerpDeployAction::RegisterAsset(RegisterAsset {
max_gas: Some(1000000),
asset_request: RegisterAssetRequest {
coin: "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?;
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 signingExtending Signers:
Implement the Signer
trait for custom signing backends like hardware wallets, remote signers, or multi-party computation systems.
MIT License