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 a crate::Client:

ⓘ
use df_hyperliquid_core::client::web::{Web, clock};
use df_hyperliquid_core::{Client, Network};

let client = Client::reader(Web, Network::Mainnet, clock);

and a crate::live::Session to the feed, then read the crate::live::Events it hands back:

ⓘ
use df_hyperliquid_core::Network;
use df_hyperliquid_core::client::web::Feed;
use df_hyperliquid_core::live::{Session, Subscription};

let mut feed = Feed::start(Session::new(Network::Mainnet));
feed.subscribe(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::Feed;

Modules§

socket
The websocket in the browser and Workers: a Feed carries one crate::live::Session over the global WebSocket and hands back crate::live::Events. 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.