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
impl HyperliquidAdapter
pub fn new() -> Self
pub fn new() -> Self
An adapter for public mainnet market data.
pub fn testnet() -> Self
pub fn testnet() -> Self
An adapter for public testnet market data.
pub fn with_query_address(self, address: impl Into<String>) -> Self
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
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
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
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>>
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>
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>
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>
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>
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>>
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>>
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>>
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>>
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>>
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>>
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>
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>>
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>
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>>
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>
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>>
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>>
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>>
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>
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>
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>
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>>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
pub async fn subscribe_detailed_account_with( &self, config: &StreamConfig, ) -> Result<HyperliquidAccountStream>
Opens a full-fidelity account subscription with explicit connection settings.