Skip to main content

HyperliquidAdapter

Struct HyperliquidAdapter 

pub struct HyperliquidAdapter { /* private fields */ }
Expand description

Adapter for Hyperliquid spot and default perpetual markets.

Public market-data calls do not require configuration. Public account reads use HyperliquidAdapter::with_query_address; signed actions use HyperliquidAdapter::with_signer. HyperliquidAdapter::with_wallet configures both for compatibility and convenience.

Markets are loaded from meta and spotMeta. HIP-3 DEXes and outcome markets are not exposed by this adapter.

Client::trades uses recentTrades, which exposes at most ten recent executions and no historical range. Feed::Trades provides live updates but may have a gap after reconnection.

Ticker::last_price uses midPx, falling back to markPx; it is not the latest execution price. Use the trades API when an execution price and trade time are required.

Provider-specific data is available through the account Info methods, HyperliquidAdapter::non_funding_ledger, and HyperliquidAdapter::asset_context.

Implementations§

§

impl HyperliquidAdapter

pub fn new() -> Self

An adapter for public mainnet market data.

pub fn testnet() -> Self

An adapter for public testnet market data.

pub fn with_query_address(self, address: impl Into<String>) -> Self

Configures an account address for public account-data queries.

Hyperliquid’s Info API requires the public master or subaccount address, but no signature. The value is validated when an account read is made.

pub fn with_signer(self, private_key: impl Into<String>) -> Self

Configures the local key used only for signed actions.

This may be an approved API-wallet key and therefore does not identify the account queried by the Info API. The key is redacted from Debug output and validated before any network request is made. Use a separate API wallet for each process; Hyperliquid tracks nonces by signer.

pub fn with_wallet( self, address: impl Into<String>, private_key: impl Into<String>, ) -> Self

Configures the public query address and local signer together.

address is the account acted on. private_key is either that account’s key or an approved API wallet key. The key is used only for local signing and is redacted from Debug output.

The address may be the master account while private_key belongs to an approved API wallet. This is equivalent to calling HyperliquidAdapter::with_query_address and HyperliquidAdapter::with_signer.

pub fn is_testnet(&self) -> bool

Whether this adapter talks to testnet.

pub async fn non_funding_ledger( &self, from: Option<Timestamp>, to: Option<Timestamp>, cursor: Option<&Cursor>, limit: Option<u32>, ) -> Result<Page<HyperliquidLedgerEntry>>

Reads account-wide non-funding ledger entries.

Entries include deposits, withdrawals, transfers, and liquidations. They are distinct from market-scoped FundingPayment records. See HyperliquidLedgerEntry.

Pass Page::next back as cursor until it is None.

§Errors

Returns Error::Auth when no valid query address is configured. Invalid cursors, transport failures, exchange errors, and payload changes are also returned.

pub async fn user_rate_limit(&self) -> Result<HyperliquidUserRateLimit>

Reads the configured account’s current Info API request allowance.

This is a public account read: it needs an address but no signature.

pub async fn user_role(&self) -> Result<HyperliquidUserRole>

Reads the configured account’s Hyperliquid role.

Unknown provider role names remain available as HyperliquidUserRole::Other. This is a public account read and does not use the local signer.

pub async fn referral(&self) -> Result<HyperliquidReferral>

Reads the configured account’s referral state.

Stable balances are parsed exactly; provider-owned nested program state remains JSON so an added referral stage does not discard data.

pub async fn user_fees(&self) -> Result<HyperliquidUserFees>

Reads the configured account’s fee schedule and current fee rates.

The full provider fee schedule is retained because Hyperliquid can add product tiers independently of the common order-fee model.

pub async fn portfolio(&self) -> Result<Vec<HyperliquidPortfolioPeriod>>

Reads the configured account’s portfolio history by provider period.

pub async fn sub_accounts(&self) -> Result<Vec<HyperliquidSubAccount>>

Reads the configured account’s subaccounts.

Hyperliquid returns null when an account has none; this method returns an empty list for that documented absence.

pub async fn user_vault_equities(&self) -> Result<Vec<HyperliquidVaultEquity>>

Reads the configured account’s current vault equity positions.

pub async fn user_fills( &self, aggregate_by_time: bool, ) -> Result<Vec<HyperliquidUserFill>>

Reads the configured account’s most recent fills.

Hyperliquid returns at most 2,000 fills. Set aggregate_by_time to combine eligible partial fills using Hyperliquid’s documented rule. The provider-specific HyperliquidUserFill preserves execution, account-position, fee, and raw provider data without widening the common Trade contract.

§Errors

Returns Error::Auth before any network request when no valid query address is configured.

pub async fn user_fills_by_time( &self, from: Timestamp, to: Option<Timestamp>, aggregate_by_time: bool, ) -> Result<Vec<HyperliquidUserFill>>

Reads the configured account’s fills in the inclusive provider time range.

from maps to Hyperliquid’s required startTime; to, when present, maps to its optional inclusive endTime. Hyperliquid returns at most 2,000 fills per response and retains only its 10,000 most recent fills. Set aggregate_by_time to use the provider’s partial-fill aggregation.

§Errors

Returns Error::Auth before any network request when no valid query address is configured.

pub async fn basic_open_orders(&self) -> Result<Vec<HyperliquidOpenOrder>>

Reads the configured account’s compact openOrders response.

This provider-specific method is deliberately named basic_open_orders to distinguish it from the common open-order API, which uses the richer frontendOpenOrders response.

§Errors

Returns Error::Auth before any network request when no valid query address is configured.

pub async fn order_status( &self, reference: HyperliquidOrderReference, ) -> Result<HyperliquidOrderStatusResponse>

Queries one order by server order id or 16-byte client order id.

Hyperliquid’s documented unknownOid response is returned as HyperliquidOrderStatusResponse::UnknownOrder, not as an error.

§Errors

Returns Error::Auth before any network request when no valid query address is configured. Malformed client order ids return Error::InvalidRequest.

pub async fn historical_orders(&self) -> Result<Vec<HyperliquidOrderInfo>>

Reads up to Hyperliquid’s 2,000 most recent historical orders.

Status and order enum strings remain in their provider spelling, and each record retains the full response object as JSON.

§Errors

Returns Error::Auth before any network request when no valid query address is configured.

pub async fn asset_context( &self, market: &Market, ) -> Result<HyperliquidAssetContext>

Reads the current asset context for one market.

The context includes mid, mark, and oracle prices; the current funding rate; open interest; and order precision. Historical market-rate observations use FundingRate, while actual account charges use FundingPayment. See HyperliquidAssetContext.

§Errors

Returns an error for an unlisted or non-Hyperliquid market, a transport or exchange failure, or an invalid response payload.

pub async fn candle_snapshot( &self, market: &Market, interval: &str, from: Timestamp, to: Option<Timestamp>, ) -> Result<Vec<HyperliquidCandleSnapshot>>

Reads one raw candle snapshot window with Hyperliquid’s trade count intact.

interval must use Hyperliquid’s documented spelling such as "1m". from is required and maps to startTime; to, when supplied, maps to the provider’s inclusive endTime.

pub async fn l2_book(&self, market: &Market) -> Result<HyperliquidL2Book>

Reads an L2 snapshot with Hyperliquid’s order count for every level.

pub async fn recent_trades( &self, market: &Market, ) -> Result<Vec<HyperliquidRecentTrade>>

Reads the provider’s recent trades without dropping hashes or account lists.

Hyperliquid returns at most ten entries and accepts no count parameter.

pub async fn funding_history( &self, market: &Market, from: Timestamp, to: Option<Timestamp>, ) -> Result<Vec<HyperliquidFundingHistoryEntry>>

Reads historical funding observations with Hyperliquid’s premium index.

The supplied time bounds map directly to Hyperliquid’s millisecond startTime and optional inclusive endTime.

pub async fn user_funding( &self, from: Timestamp, to: Option<Timestamp>, ) -> Result<Vec<HyperliquidUserFunding>>

Reads account funding records with position size and sample count intact.

This is a public account read and needs a configured query address, not a signing key.

pub async fn spot_clearinghouse_state( &self, ) -> Result<HyperliquidSpotClearinghouseState>

Reads the configured account’s spot state with entry notional intact.

pub async fn spot_meta(&self) -> Result<HyperliquidSpotMeta>

Reads all spot token and pair metadata without narrowing provider fields.

pub async fn spot_meta_and_asset_contexts( &self, ) -> Result<HyperliquidSpotMetaAndAssetContexts>

Reads spot metadata and asset contexts without dropping supply fields.

pub async fn all_mids(&self) -> Result<Vec<HyperliquidMidPrice>>

Reads the current mid price for every market in the default universe.

Hyperliquid’s allMids Info API uses the first perpetual DEX when no dex is supplied, and includes spot mids in that response. The returned price may fall back to the latest trade when a book is empty; the endpoint does not attach a timestamp.

HIP-3 DEX markets are not included because this adapter’s market table intentionally covers only the default perpetual and spot universes.

pub async fn all_mids_detail(&self) -> Result<HyperliquidAllMids>

Reads current mids while preserving Hyperliquid’s complete provider map.

pub async fn perpetual_meta(&self) -> Result<HyperliquidProviderResponse>

Reads the complete perpetual meta response without narrowing it to the portable market-list contract.

pub async fn perpetual_meta_and_asset_contexts( &self, ) -> Result<HyperliquidProviderResponse>

Reads the complete perpetual metaAndAssetCtxs response without narrowing it to portable ticker fields.

pub async fn clearinghouse_state_detail( &self, ) -> Result<HyperliquidProviderResponse>

Reads the complete perpetual clearinghouse state for the configured public query address.

pub async fn frontend_open_orders_detail( &self, ) -> Result<HyperliquidProviderResponse>

Reads the complete frontendOpenOrders response for the configured public query address.

pub async fn place_order_detail( &self, request: &OrderRequest, ) -> Result<HyperliquidOrderActionResponse>

Places an order while retaining the complete signed action response.

pub async fn cancel_order_detail( &self, market: &Market, order_id: &str, ) -> Result<HyperliquidProviderResponse>

Cancels an order while retaining the complete signed action response.

pub async fn subscribe_detailed( &self, subscription: &Subscription, ) -> Result<HyperliquidMarketStream>

Opens a full-fidelity market subscription with default connection settings.

The returned events retain the documented Hyperliquid fields that the portable MarketStream deliberately omits. Use Self::subscribe_detailed_with to set reconnect and buffering rules.

pub async fn subscribe_detailed_with( &self, subscription: &Subscription, config: &StreamConfig, ) -> Result<HyperliquidMarketStream>

Opens a full-fidelity market subscription with explicit connection settings.

pub async fn subscribe_detailed_account( &self, ) -> Result<HyperliquidAccountStream>

Opens a full-fidelity account subscription with default connection settings.

This public account read needs a configured query address, but no local signature. Use Self::subscribe_detailed_account_with to set reconnect and buffering rules.

pub async fn subscribe_detailed_account_with( &self, config: &StreamConfig, ) -> Result<HyperliquidAccountStream>

Opens a full-fidelity account subscription with explicit connection settings.

Trait Implementations§

§

impl Adapter for HyperliquidAdapter

§

fn exchange(&self) -> Exchange

Which exchange this adapter talks to.
§

fn supports(&self, feature: Feature) -> bool

Whether this configured adapter can use a feature. Read more
§

fn trades( &self, market: &Market, limit: Option<u32>, ) -> BoxFuture<'_, Result<Vec<Trade>>>

Reads the most recent trades on a market.
§

fn markets(&self, kind: MarketKind) -> BoxFuture<'_, Result<Vec<MarketInfo>>>

Lists the exchange’s markets of one kind.
§

fn order_book( &self, market: &Market, depth: Option<u32>, ) -> BoxFuture<'_, Result<OrderBook>>

Reads an order book snapshot.
§

fn ticker(&self, market: &Market) -> BoxFuture<'_, Result<Ticker>>

Reads a provider ticker summary for one market.
§

fn candles(&self, request: &CandleRequest) -> BoxFuture<'_, Result<Vec<Candle>>>

Reads historical candles.
§

fn subscribe( &self, subscription: &Subscription, config: &StreamConfig, ) -> BoxFuture<'_, Result<MarketStream>>

Opens a live market-data subscription. Read more
§

fn balances(&self) -> BoxFuture<'_, Result<Vec<Balance>>>

Reads the account’s balances.
§

fn deposits( &self, request: &TransferHistoryRequest, ) -> BoxFuture<'_, Result<Page<Deposit>>>

Reads one page of deposit history.
§

fn withdrawals( &self, request: &TransferHistoryRequest, ) -> BoxFuture<'_, Result<Page<Withdrawal>>>

Reads one page of withdrawal history.
§

fn open_orders( &self, market: Option<&Market>, ) -> BoxFuture<'_, Result<Vec<Order>>>

Reads the account’s open orders, optionally narrowed to one market.
§

fn subscribe_account( &self, config: &StreamConfig, ) -> BoxFuture<'_, Result<AccountStream>>

Opens a live private account subscription. Read more
§

fn place_order(&self, request: &OrderRequest) -> BoxFuture<'_, Result<Order>>

Places an order.
§

fn cancel_order( &self, market: &Market, order_id: &str, ) -> BoxFuture<'_, Result<()>>

Cancels an order by the exchange’s own identifier.
§

fn positions( &self, market: Option<&Market>, ) -> BoxFuture<'_, Result<Vec<Position>>>

Reads open positions, optionally narrowed to one market.
§

fn margin_summary(&self) -> BoxFuture<'_, Result<MarginSummary>>

Reads account-wide margin state.
§

fn funding_rates( &self, request: &HistoryRequest, ) -> BoxFuture<'_, Result<Page<FundingRate>>>

Reads a market’s funding rate history.
§

fn funding_payments( &self, request: &HistoryRequest, ) -> BoxFuture<'_, Result<Page<FundingPayment>>>

Reads the account’s funding payment history.
§

fn set_margin(&self, request: &MarginRequest) -> BoxFuture<'_, Result<()>>

Sets leverage or margin mode on a market.
§

fn order_rules(&self, market: &Market) -> BoxFuture<'_, Result<OrderRules>>

Reads current order fees, limits, supported combinations, and balances.
§

fn asset_networks( &self, asset: &str, ) -> BoxFuture<'_, Result<Vec<AssetNetwork>>>

Reads live transfer rules for one asset.
§

fn deposit_addresses(&self) -> BoxFuture<'_, Result<Vec<DepositAddressEntry>>>

Lists all exchange-issued deposit addresses for this account. Read more
§

fn deposit_address( &self, request: &DepositAddressRequest, ) -> BoxFuture<'_, Result<DepositAddress>>

Reads an exchange-issued deposit address.
§

fn create_deposit_address( &self, request: &DepositAddressRequest, ) -> BoxFuture<'_, Result<DepositAddress>>

Requests creation of an exchange-issued deposit address. Read more
§

fn prepare_withdrawal( &self, request: &WithdrawRequest, ) -> BoxFuture<'_, Result<WithdrawalQuote>>

Performs live source-account checks without submitting a withdrawal.
§

fn withdraw( &self, request: &WithdrawRequest, ) -> BoxFuture<'_, Result<Withdrawal>>

Submits one withdrawal without automatic retry.
§

fn deposit( &self, request: &TransferLookupRequest, ) -> BoxFuture<'_, Result<Deposit>>

Looks up one deposit by exchange UUID or transaction ID.
§

fn withdrawal( &self, request: &TransferLookupRequest, ) -> BoxFuture<'_, Result<Withdrawal>>

Looks up one withdrawal by exchange UUID or transaction ID.
§

fn cancel_withdrawal(&self, withdrawal_id: &str) -> BoxFuture<'_, Result<()>>

Cancels a withdrawal that the exchange still permits to be cancelled.
§

fn order(&self, market: &Market, order_id: &str) -> BoxFuture<'_, Result<Order>>

Reads one order by the exchange’s own identifier.
§

fn order_by_client_id( &self, market: &Market, client_id: &str, ) -> BoxFuture<'_, Result<Order>>

Reads one order by the caller-assigned identifier supplied at placement.
§

fn orders_by_ids( &self, request: &OrderLookupRequest, ) -> BoxFuture<'_, Result<Vec<Order>>>

Looks up up to 100 orders by exchange or caller-assigned identifiers.
§

fn order_history( &self, request: &OrderHistoryRequest, ) -> BoxFuture<'_, Result<Page<Order>>>

Reads one newest-first page of completed or cancelled orders.
§

fn cancel_order_by_client_id( &self, market: &Market, client_id: &str, ) -> BoxFuture<'_, Result<()>>

Cancels an order by the caller-assigned identifier supplied at placement.
§

fn cancel_orders( &self, request: &CancelOrdersRequest, ) -> BoxFuture<'_, Result<CancelOrdersResult>>

Cancels multiple orders and returns every per-order outcome.
§

impl Clone for HyperliquidAdapter

§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for HyperliquidAdapter

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
§

impl Default for HyperliquidAdapter

§

fn default() -> Self

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

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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