pub struct HyperliquidClient { /* private fields */ }Implementations§
Source§impl HyperliquidClient
impl HyperliquidClient
pub fn new() -> Self
Sourcepub fn with_auth(user_address: impl Into<String>, private_key: String) -> Self
pub fn with_auth(user_address: impl Into<String>, private_key: String) -> Self
Examples found in repository?
5async fn main() {
6 let addr = std::env::var("HYPERLIQUID_WALLET_ADDRESS").expect("missing addr");
7 let key = std::env::var("HYPERLIQUID_WALLET_KEY").expect("missing key");
8 let client = HyperliquidClient::with_auth(addr, key);
9
10 match client.get_balance().await {
11 Ok(balances) => {
12 println!("{} balances returned:", balances.len());
13 for b in &balances {
14 println!("\n--- {} ---", b.token);
15 println!(" equity: {}", b.equity);
16 println!(" free: {}", b.free);
17 println!(" hold: {}", b.hold);
18 println!(" safe: {:?}", b.safe);
19 println!(" usable: {}", b.usable);
20 println!(" maintenance:{:?}", b.maintenance);
21 println!(" margin_used:{:?}", b.margin_used);
22 }
23 }
24 Err(e) => eprintln!("ERROR: {e}"),
25 }
26}Sourcepub fn with_budgets(self, rest_weight: u32, addr_budget: u64) -> Self
pub fn with_budgets(self, rest_weight: u32, addr_budget: u64) -> Self
Configure rate limit budgets (rest_weight/min, address_requests). Defaults: 1200 rest weight/min, 10000 address requests.
Trait Implementations§
Source§impl Default for HyperliquidClient
impl Default for HyperliquidClient
Source§impl GetAccountSnapshot for HyperliquidClient
impl GetAccountSnapshot for HyperliquidClient
Source§async fn get_positions(&self) -> Result<Vec<Position>, String>
async fn get_positions(&self) -> Result<Vec<Position>, String>
Returns open positions from clearinghouseState. Requires with_auth.
Zero-size positions are filtered out. Positive szi = long, negative = short.
Source§async fn get_open_orders(&self) -> Result<Vec<OpenOrder>, String>
async fn get_open_orders(&self) -> Result<Vec<OpenOrder>, String>
Returns resting orders from Hyperliquid’s openOrders endpoint. Requires with_auth.
filled_quantity is derived as origSz - sz (original size minus remaining size).
Source§async fn get_balance(&self) -> Result<Vec<AccountBalance>, String>
async fn get_balance(&self) -> Result<Vec<AccountBalance>, String>
Returns all per-asset balances from spotClearinghouseState with margin health.
Requires with_auth.
Source§async fn get_user_rate_limit(&self) -> Result<UserRateLimit, String>
async fn get_user_rate_limit(&self) -> Result<UserRateLimit, String>
Returns the user’s address-level API rate limit budget.
Queries Hyperliquid’s userRateLimit info endpoint for authoritative server-side counts.
Source§impl GetMarketData for HyperliquidClient
impl GetMarketData for HyperliquidClient
Source§async fn get_symbol(&self) -> Result<Vec<String>, String>
async fn get_symbol(&self) -> Result<Vec<String>, String>
Returns all perpetual asset names from Hyperliquid’s meta endpoint.
Source§async fn get_open_interest(&self, symbol: String) -> Result<Decimal, String>
async fn get_open_interest(&self, symbol: String) -> Result<Decimal, String>
Returns the current open interest for symbol from metaAndAssetCtxs.
Source§async fn get_asset_context(
&self,
symbol: String,
) -> Result<AssetContext, String>
async fn get_asset_context( &self, symbol: String, ) -> Result<AssetContext, String>
Returns a full AssetContext snapshot for symbol from metaAndAssetCtxs.
Source§async fn get_all_asset_contexts(&self) -> Result<Vec<AssetContext>, String>
async fn get_all_asset_contexts(&self) -> Result<Vec<AssetContext>, String>
Fetches metaAndAssetCtxs once and returns all asset contexts in universe order.
Prefer this over repeated get_asset_context calls to avoid rate-limiting.
Source§async fn get_sz_decimals(&self, symbol: String) -> Result<i32, String>
async fn get_sz_decimals(&self, symbol: String) -> Result<i32, String>
Returns the number of decimal places for order size for a symbol.
Source§async fn get_all_sz_decimals(&self) -> Result<HashMap<String, i32>, String>
async fn get_all_sz_decimals(&self) -> Result<HashMap<String, i32>, String>
Returns sz_decimals for all symbols from the meta universe.
Source§async fn get_l2_orderbook(&self, symbol: String) -> Result<L2Snapshot, String>
async fn get_l2_orderbook(&self, symbol: String) -> Result<L2Snapshot, String>
Returns a full L2 orderbook snapshot for symbol from the l2Book REST endpoint.
Source§async fn get_price(&self, symbol: String) -> Result<Decimal, String>
async fn get_price(&self, symbol: String) -> Result<Decimal, String>
Returns the mid-price of symbol (e.g. “BTC”) from allMids.
Source§async fn get_predicted_fundings(&self) -> Result<Vec<PredictedFunding>, String>
async fn get_predicted_fundings(&self) -> Result<Vec<PredictedFunding>, String>
Returns predicted funding rates for all symbols across all venues. Null venue entries (unsupported coins) are silently skipped.
Source§impl ManageOrder for HyperliquidClient
impl ManageOrder for HyperliquidClient
Source§async fn place_order(
&self,
symbol: String,
side: OrderSide,
price: Decimal,
volume: Decimal,
order_type: OrderType,
time_in_force: TimeInForce,
trigger_price: Option<Decimal>,
reduce_only: bool,
cloid: Option<String>,
) -> Result<OrderPlacement, String>
async fn place_order( &self, symbol: String, side: OrderSide, price: Decimal, volume: Decimal, order_type: OrderType, time_in_force: TimeInForce, trigger_price: Option<Decimal>, reduce_only: bool, cloid: Option<String>, ) -> Result<OrderPlacement, String>
Places an order on Hyperliquid. Requires with_auth. Returns an OrderPlacement with
the exchange-assigned order ID. Market orders are submitted as aggressive limit orders (IOC).
If cloid is provided, Hyperliquid attaches it to the order lifecycle — fills and order
updates will carry the same cloid back, enabling end-to-end intent tracing without a
separate order_id mapping.
Trigger orders (TakeProfit / StopLoss) require trigger_price to be set. The order
activates when the mark price reaches triggerPx, then executes as a market or limit
order depending on time_in_force (Ioc = market, Gtc = limit).
Source§async fn change_order_by_cloid(
&self,
cloid: i64,
price: Decimal,
volume: Decimal,
) -> Result<i64, String>
async fn change_order_by_cloid( &self, cloid: i64, price: Decimal, volume: Decimal, ) -> Result<i64, String>
Modifies price and size of an existing order by its order ID. Requires with_auth.
Fetches the order’s current coin and side before submitting the modify action.
Source§async fn cancel_order_by_cloid(&self, cloid: String) -> Result<(), String>
async fn cancel_order_by_cloid(&self, cloid: String) -> Result<(), String>
Cancels a single order by its client order ID (cloid). Requires with_auth.
Fetches open orders to resolve the order ID for the matching cloid, then
submits a cancel action using the order ID — this works for all order types
including trigger orders (TakeProfit/StopLoss).
Source§impl SubscribeMarketData for HyperliquidClient
impl SubscribeMarketData for HyperliquidClient
Source§async fn unsubscribe_all(&self)
async fn unsubscribe_all(&self)
Gracefully shut down all market data subscriptions. Closes all broadcast channels so subscribers exit without reconnecting.
Source§fn subscribe_l2_update(
&self,
symbol: String,
) -> BoxStream<Result<L2Update, String>>
fn subscribe_l2_update( &self, symbol: String, ) -> BoxStream<Result<L2Update, String>>
Source§fn subscribe_l2_snapshot(
&self,
symbol: String,
) -> BoxStream<Result<L2Snapshot, String>>
fn subscribe_l2_snapshot( &self, symbol: String, ) -> BoxStream<Result<L2Snapshot, String>>
Source§fn subscribe_asset_context(
&self,
symbol: String,
) -> BoxStream<Result<AssetContext, String>>
fn subscribe_asset_context( &self, symbol: String, ) -> BoxStream<Result<AssetContext, String>>
Source§fn subscribe_liquidation(
&self,
user: String,
) -> BoxStream<Result<Liquidation, String>>
fn subscribe_liquidation( &self, user: String, ) -> BoxStream<Result<Liquidation, String>>
Source§impl SubscribeMarketDataOps for HyperliquidClient
impl SubscribeMarketDataOps for HyperliquidClient
Source§async fn unsubscribe_market_data(&self, symbol: String)
async fn unsubscribe_market_data(&self, symbol: String)
Source§impl SubscribeUserEvents for HyperliquidClient
impl SubscribeUserEvents for HyperliquidClient
Source§fn subscribe_spot_balance(
&self,
) -> BoxStream<Result<Vec<AccountBalance>, String>>
fn subscribe_spot_balance( &self, ) -> BoxStream<Result<Vec<AccountBalance>, String>>
Subscribe to spot wallet balance updates for the registered user address.
Source§fn subscribe_spot_balance_with_address(
&self,
address: String,
) -> BoxStream<Result<Vec<AccountBalance>, String>>
fn subscribe_spot_balance_with_address( &self, address: String, ) -> BoxStream<Result<Vec<AccountBalance>, String>>
Subscribe to spot wallet balance updates for a specific address.