SDK for Hyperliquid API trading with Rust.
See src/bin for examples. You can run any example with cargo run --bin [EXAMPLE].
cargo add hyperliquid_rust_sdk
For an outcome-market-only integration, disable the default full SDK surface and enable the
outcomes feature:
hyperliquid_rust_sdk = { version = "0.6", default-features = false, features = ["outcomes"] }Enable live outcome feeds separately when needed:
hyperliquid_rust_sdk = { version = "0.6", default-features = false, features = ["outcome-websocket"] }The outcomes feature exposes OutcomeClient, outcome metadata types, and helpers for HIP-4
outcome asset IDs without the full perp, spot, websocket, or market-maker surface.
use alloy::signers::local::PrivateKeySigner;
use hyperliquid_rust_sdk::{
BaseUrl, OutcomeClient, OutcomeLimit, OutcomeOrderRequest, OutcomeOrderType,
};
# async fn example(wallet: PrivateKeySigner) -> Result<(), hyperliquid_rust_sdk::Error> {
let client = OutcomeClient::new(None, Some(BaseUrl::Testnet), None).await?;
let meta = client.outcome_meta().await?;
let questions = client.resolved_outcome_questions().await?;
let order = OutcomeOrderRequest {
outcome: meta.outcomes[0].outcome,
side_index: 0,
is_buy: true,
reduce_only: false,
limit_px: 0.42,
sz: 10.0,
cloid: None,
order_type: OutcomeOrderType::Limit(OutcomeLimit {
tif: "Gtc".to_string(),
}),
};
client.order(&wallet, order).await?;
# Ok(())
# }use hyperliquid_rust_sdk::{BaseUrl, OutcomeSubscription, OutcomeWsClient};
# async fn ws_example() -> Result<(), hyperliquid_rust_sdk::Error> {
let mut ws = OutcomeWsClient::connect(Some(BaseUrl::Testnet)).await?;
ws.subscribe(&OutcomeSubscription::L2Book {
outcome: 7003,
side_index: 0,
})
.await?;
if let Some(message) = ws.next_message().await? {
let side = message.outcome_side();
}
# Ok(())
# }This project is licensed under the terms of the MIT license. See LICENSE for more details.
@misc{hyperliquid-rust-sdk,
author = {Hyperliquid},
title = {SDK for Hyperliquid API trading with Rust.},
year = {2024},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/hyperliquid-dex/hyperliquid-rust-sdk}}
}