@nktkas/hyperliquid
Version:
Hyperliquid API SDK for all major JS runtimes, written in TypeScript.
53 lines (52 loc) • 2.04 kB
JavaScript
import * as v from "valibot";
// ============================================================
// API Schemas
// ============================================================
/**
* Subscription to explorer block events.
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
*/ export const ExplorerBlockRequest = /* @__PURE__ */ (()=>{
return v.object({
/** Type of subscription. */ type: v.literal("explorerBlock")
});
})();
// ============================================================
// Execution Logic
// ============================================================
import { parse } from "../../../_base.js";
/**
* Subscribe to explorer block updates.
*
* @param config General configuration for Explorer API subscriptions.
* @param listener A callback function to be called when the event is received.
* @param onError An optional callback function to be called when the subscription fails.
* @return A request-promise that resolves with a {@link ISubscription} object to manage the subscription lifecycle.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
*
* @example
* ```ts
* import { WebSocketTransport } from "@nktkas/hyperliquid";
* import { explorerBlock } from "@nktkas/hyperliquid/api/explorer";
*
* const transport = new WebSocketTransport({ url: "wss://rpc.hyperliquid.xyz/ws" }); // only `WebSocketTransport` supports this API
*
* const sub = await explorerBlock(
* { transport },
* (data) => console.log(data),
* );
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
*/ export function explorerBlock(config, listener, onError) {
const payload = parse(ExplorerBlockRequest, {
type: "explorerBlock"
});
return config.transport.subscribe("explorerBlock_", payload, (e)=>{
listener(e.detail);
}, {
onError
});
}
//# sourceMappingURL=explorerBlock.js.map