@nktkas/hyperliquid
Version:
Hyperliquid API SDK for all major JS runtimes, written in TypeScript.
50 lines (49 loc) • 1.89 kB
JavaScript
import * as v from "valibot";
/**
* Subscription to explorer transaction events.
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
*/ export const ExplorerTxsRequest = /* @__PURE__ */ (()=>{
return v.object({
/** Type of subscription. */ type: v.literal("explorerTxs")
});
})();
// ============================================================
// Execution Logic
// ============================================================
import { parse } from "../../../_base.js";
/**
* Subscribe to explorer transaction 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 { explorerTxs } from "@nktkas/hyperliquid/api/explorer";
*
* const transport = new WebSocketTransport({ url: "wss://rpc.hyperliquid.xyz/ws" }); // only `WebSocketTransport` supports this API
*
* const sub = await explorerTxs(
* { transport },
* (data) => console.log(data),
* );
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
*/ export function explorerTxs(config, listener, onError) {
const payload = parse(ExplorerTxsRequest, {
type: "explorerTxs"
});
return config.transport.subscribe("explorerTxs_", payload, (e)=>{
listener(e.detail);
}, {
onError
});
}
//# sourceMappingURL=explorerTxs.js.map