Skip to main content

Module web

Module web 

Source
Expand description

HTTP and websocket for the browser and Workers: Web sends requests through the global fetch, clock is Date.now(), and a Feed keeps the websocket open over the global WebSocket. Hand the first two to crate::client::Api:

ⓘ
let api = df_hyperliquid_core::client::Api::new(df_hyperliquid_core::client::web::Web, df_hyperliquid_core::client::Network::Mainnet, df_hyperliquid_core::client::web::clock);

and an crate::live::Session to the feed, then read what it hands back:

ⓘ
let mut feed = df_hyperliquid_core::client::web::Feed::start(df_hyperliquid_core::live::Session::new(df_hyperliquid_core::client::Network::Mainnet));
feed.subscribe(df_hyperliquid_core::live::Subscription::AllMids { dex: String::new() }).await?;
while let Some(event) = feed.next().await {
    // Opened, Frame, Unreadable, or Closed with the delay before the next dial.
}

fetch, WebSocket and setTimeout are read off the global object, so this runs in a page, a Web Worker, a Cloudflare Worker and Node 22. The API answers CORS with *. Requests are never retried.

Re-exports§

pub use socket::Event;
pub use socket::Feed;
pub use socket::FeedError;

Modules§

socket
The websocket in the browser and Workers: a Feed carries one crate::live::Session over the global WebSocket. Subscriptions made while down are sent on the next open; a post made while down is refused, and one cut off by a drop is reported, never resent.

Structs§

Web
The global fetch.

Functions§

clock
Unix milliseconds from Date.now(): the crate::client::Clock in the browser and Workers, where std has no clock.