Skip to main content

HyperliquidClient

Struct HyperliquidClient 

Source
pub struct HyperliquidClient { /* private fields */ }

Implementations§

Source§

impl HyperliquidClient

Source

pub fn new() -> Self

Source

pub fn with_auth(user_address: impl Into<String>, private_key: String) -> Self

Examples found in repository?
examples/check_balance.rs (line 8)
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}
Source

pub fn with_external_signer( user_address: impl Into<String>, signer: Arc<dyn ExternalSigner>, ) -> Self

Create a client authenticated via an external signer (TPM, Secure Enclave, etc.).

The signer handles the actual ECDSA signing; the private key never leaves the hardware. The client computes the EIP-712 digest and delegates signing to the external signer.

Source

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

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl GetAccountSnapshot for HyperliquidClient

Source§

fn get_positions<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<Position>, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns open positions from clearinghouseState. Requires with_auth. Zero-size positions are filtered out. Positive szi = long, negative = short.

Source§

fn get_open_orders<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<OpenOrder>, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns resting orders from Hyperliquid’s openOrders endpoint. Requires with_auth. filled_quantity is derived as origSz - sz (original size minus remaining size).

Source§

fn get_balance<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<AccountBalance>, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns all per-asset balances from spotClearinghouseState with margin health. Also fetches clearinghouseState to populate margin_used on the USDC entry. Requires with_auth.

Source§

fn get_user_rate_limit<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<UserRateLimit, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

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

Source§

fn get_symbol<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns all perpetual asset names from Hyperliquid’s meta endpoint.

Source§

fn get_open_interest<'life0, 'async_trait>( &'life0 self, symbol: String, ) -> Pin<Box<dyn Future<Output = Result<Decimal, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns the current open interest for symbol from metaAndAssetCtxs.

Source§

fn get_asset_context<'life0, 'async_trait>( &'life0 self, symbol: String, ) -> Pin<Box<dyn Future<Output = Result<AssetContext, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns a full AssetContext snapshot for symbol from metaAndAssetCtxs.

Source§

fn get_all_asset_contexts<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<AssetContext>, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Fetches metaAndAssetCtxs once and returns all asset contexts in universe order. Prefer this over repeated get_asset_context calls to avoid rate-limiting.

Source§

fn get_sz_decimals<'life0, 'async_trait>( &'life0 self, symbol: String, ) -> Pin<Box<dyn Future<Output = Result<i32, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns the number of decimal places for order size for a symbol.

Source§

fn get_all_sz_decimals<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<HashMap<String, i32>, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns sz_decimals for all symbols from the meta universe.

Source§

fn get_l2_orderbook<'life0, 'async_trait>( &'life0 self, symbol: String, ) -> Pin<Box<dyn Future<Output = Result<L2Snapshot, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns a full L2 orderbook snapshot for symbol from the l2Book REST endpoint.

Source§

fn get_price<'life0, 'async_trait>( &'life0 self, symbol: String, ) -> Pin<Box<dyn Future<Output = Result<Decimal, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns the mid-price of symbol (e.g. “BTC”) from allMids.

Source§

fn get_predicted_fundings<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<PredictedFunding>, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns predicted funding rates for all symbols across all venues. Null venue entries (unsupported coins) are silently skipped.

Source§

impl ManageOrder for HyperliquidClient

Source§

fn place_order<'life0, 'async_trait>( &'life0 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>, ) -> Pin<Box<dyn Future<Output = Result<OrderPlacement, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

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§

fn change_order_by_cloid<'life0, 'async_trait>( &'life0 self, cloid: i64, price: Decimal, volume: Decimal, ) -> Pin<Box<dyn Future<Output = Result<i64, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

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§

fn cancel_order_by_cloid<'life0, 'async_trait>( &'life0 self, cloid: String, ) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

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§

fn cancel_all_order<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<bool, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Cancels all open orders. Requires with_auth. Fetches all open orders and submits a batch cancel in a single signed request.

Source§

impl SubscribeMarketData for HyperliquidClient

Source§

fn unsubscribe_all<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

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>>

subscribe to L2 orderbook updates for a symbol
Source§

fn subscribe_l2_snapshot( &self, symbol: String, ) -> BoxStream<Result<L2Snapshot, String>>

subscribe to full L2 orderbook snapshots for a symbol
Source§

fn subscribe_asset_context( &self, symbol: String, ) -> BoxStream<Result<AssetContext, String>>

subscribe to asset context updates (OI, funding rate, mark price, 24h volume)
Source§

fn subscribe_liquidation( &self, user: String, ) -> BoxStream<Result<Liquidation, String>>

subscribe to liquidation events for a user address
Source§

fn subscribe_fill(&self, symbol: String) -> BoxStream<Result<Fill, String>>

subscribe to market fill events for a symbol
Source§

impl SubscribeMarketDataOps for HyperliquidClient

Source§

fn unsubscribe_market_data<'life0, 'async_trait>( &'life0 self, symbol: String, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

unsubscribe from market data streams for a symbol
Source§

impl SubscribeUserEvents for HyperliquidClient

Source§

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>>

Subscribe to spot wallet balance updates for a specific address.

Source§

fn subscribe_user_fills(&self) -> BoxStream<Result<UserFill, String>>

stream executions of the user’s own orders
Source§

fn subscribe_order_updates(&self) -> BoxStream<Result<OrderUpdate, String>>

stream order lifecycle updates
Source§

fn subscribe_funding_payments( &self, ) -> BoxStream<Result<FundingPayment, String>>

stream funding payments applied to positions
Source§

fn subscribe_deposits(&self) -> BoxStream<Result<Deposit, String>>

stream account deposit events
Source§

fn subscribe_withdrawals(&self) -> BoxStream<Result<Withdrawal, String>>

stream account withdrawal events
Source§

fn unsubscribe_user_events<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

unsubscribe from all user event streams
Source§

impl TestServer for HyperliquidClient

Source§

fn ping<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<bool, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Sends a lightweight allMids request; returns true if the server responds 200 OK.

Source§

fn get_server_time<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<i64, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Hyperliquid has no dedicated server-time endpoint; returns local UTC ms.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more