Skip to main content

Module hyperliquid

Module hyperliquid 

Source
Expand description

Hyperliquid and HyperliquidSpot Connector and StreamSelector implementations (behind hyperliquid feature). Hyperliquid market data connectors for perpetual futures and spot trading.

Uses raw WebSocket connection to wss://api.hyperliquid.xyz/ws for market data streams. Reuses hyperliquid_rust_sdk types for deserialization.

§Connectors

  • Hyperliquid: Perpetual futures market data
  • HyperliquidSpot: Spot trading market data

§Supported Streams

§Coins

A subscription names its market by a coin, exactly as Hyperliquid spells it:

  • a perpetual by its asset (BTC, kPEPE), or a builder-deployed (HIP-3) one by its deployer and asset (xyz:TSLA);
  • a spot pair by @{index} (@107 is HYPE/USDC), except PURR/USDC, named PURR/USDC.

A wrong coin gets no data, and the server then closes the connection, ending the other subscriptions on it as well. So read the coins with HyperliquidMeta and subscribe with a MarketInstrumentData built from them:

ⓘ
use rustrade_data::{
    exchange::hyperliquid::{HyperliquidMeta, HyperliquidSpot, Network},
    instrument::MarketInstrumentData,
    streams::Streams,
    subscriber::WebSocketSubscriber,
    subscription::{Subscription, trade::PublicTrades},
};

let meta = HyperliquidMeta::fetch(Network::Mainnet, &[]).await?;
let hype = meta.spot_pair("HYPE", "USDC").ok_or("no such pair")?; // `@107`

let streams = Streams::<PublicTrades>::builder()
    .subscribe(
        WebSocketSubscriber,
        [Subscription {
            exchange: HyperliquidSpot,
            instrument: MarketInstrumentData::hyperliquid_spot("hype_usdc", hype),
            kind: PublicTrades,
        }],
    )
    .init()
    .await?;

A MarketInstrumentData is subscribed by its name_exchange verbatim. A subscription built from a MarketDataInstrument instead derives the coin from asset names, which lose their case, and works only for some markets. See market.

§Notes

  • Market data streams are unauthenticated (public data)
  • Execution client uses SDK’s WebSocket separately for user data
  • Spot and perps use the same WebSocket endpoint and protocol

Re-exports§

pub use meta::HyperliquidMeta;
pub use meta::HyperliquidMetaError;

Modules§

book
channel
historical
Historical data fetcher for Hyperliquid.
market
The coin a Hyperliquid subscription names its market by.
meta
Hyperliquid’s market metadata: the coin each perpetual and spot pair is subscribed by.
subscription
trade

Structs§

Hyperliquid
Hyperliquid perpetual futures exchange connector.
HyperliquidSpot
Hyperliquid spot trading exchange connector.

Enums§

Network
A Hyperliquid network. Serialized in lower case ("mainnet", "testnet").

Constants§

BASE_URL_HYPERLIQUID
Hyperliquid mainnet WebSocket URL.

Type Aliases§

HyperliquidWsStream
Type alias for Hyperliquid WebSocket stream.