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: Address, private_key: String) -> Self

Trait Implementations§

Source§

impl GetAccountSnapshot for HyperliquidClient

Source§

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>

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_collateral(&self) -> Result<Decimal, String>

Returns total account value (collateral) from clearinghouseState. Requires with_auth.

Source§

impl GetMarketData for HyperliquidClient

Source§

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>

Returns the current open interest for symbol from metaAndAssetCtxs.

Source§

async fn get_asset_context( &self, symbol: String, ) -> Result<AssetContext, String>

Returns a full AssetContext snapshot for symbol from metaAndAssetCtxs.

Source§

async fn get_l2_orderbook( &self, symbol: String, ) -> Result<Vec<L2Update>, String>

Returns a full L2 orderbook snapshot for symbol from the l2Book REST endpoint. Levels are returned as individual L2Update items; all share the same sequence (timestamp).

Source§

async fn get_price(&self, symbol: String) -> Result<Decimal, String>

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

Source§

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, ) -> 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).

Source§

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(&self, cloid: i64) -> Result<i64, String>

Cancels a single order by its order ID. Requires with_auth. Fetches open orders to resolve the coin/asset before cancelling.

Source§

async fn cancel_all_order(&self) -> Result<bool, String>

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 subscribe_l2_update(&self, symbol: String) -> BoxStream<L2Update>

Streams L2 orderbook updates for symbol. Each message from Hyperliquid is a full-depth snapshot; every level is emitted as an individual L2Update event. All levels in the same snapshot share the same sequence value.

Source§

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

Streams asset context updates for symbol via Hyperliquid’s activeAssetCtx subscription.

Source§

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

Streams liquidation events for a user address via Hyperliquid’s userEvents subscription. Hyperliquid’s liquidation event is account-level; symbol is empty and side is Sell.

Source§

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

Streams public trade fills for symbol. “B” (buyer aggressor) → Buy, otherwise → Sell.

Source§

impl SubscribeUserEvents for HyperliquidClient

Source§

fn subscribe_user_fills(&self) -> BoxStream<UserFill>

Streams the user’s own order executions via the userEvents WS subscription. Requires with_auth (streams are empty if no user address is set).

Source§

fn subscribe_order_updates(&self) -> BoxStream<OrderUpdate>

Streams order lifecycle events via the orderUpdates WS subscription. Requires with_auth.

Source§

fn subscribe_funding_payments(&self) -> BoxStream<FundingPayment>

Streams funding payments applied to positions via the userEvents WS subscription. Requires with_auth.

Source§

fn subscribe_deposits(&self) -> BoxStream<Deposit>

stream account deposit events
Source§

fn subscribe_withdrawals(&self) -> BoxStream<Withdrawal>

stream account withdrawal events
Source§

impl TestServer for HyperliquidClient

Source§

async fn ping(&self) -> Result<bool, String>

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

Source§

async fn get_server_time(&self) -> Result<i64, String>

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

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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