@nktkas/hyperliquid
Version:
Hyperliquid API SDK for all major JS runtimes, written in TypeScript.
83 lines • 3.5 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExplorerTxsEvent = exports.ExplorerTxsRequest = void 0;
exports.explorerTxs = explorerTxs;
const v = __importStar(require("valibot"));
// ============================================================
// API Schemas
// ============================================================
const commonSchemas_js_1 = require("../../info/_methods/_base/commonSchemas.js");
/** Subscription to explorer transaction events. */
exports.ExplorerTxsRequest = (() => {
return v.pipe(v.object({
/** Type of subscription. */
type: v.pipe(v.literal("explorerTxs"), v.description("Type of subscription.")),
}), v.description("Subscription to explorer transaction events."));
})();
/** Event of array of transaction details. */
exports.ExplorerTxsEvent = (() => {
return v.pipe(v.array(commonSchemas_js_1.ExplorerTransactionSchema), v.description("Event of array of transaction details."));
})();
/**
* Subscribe to explorer transaction updates.
*
* @param config - General configuration for Subscription API subscriptions.
* @param listener - A callback function to be called when the event is received.
* @returns A request-promise that resolves with a {@link ISubscription} object to manage the subscription lifecycle.
*
* @throws {ValiError} 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/subscription";
*
* const transport = new WebSocketTransport({ url: "wss://rpc.hyperliquid.xyz/ws" }); // only `WebSocketTransport`; RPC endpoint
*
* const sub = await explorerTxs(
* { transport },
* (data) => console.log(data),
* );
* ```
*/
function explorerTxs(config, listener) {
const payload = v.parse(exports.ExplorerTxsRequest, { type: "explorerTxs" });
return config.transport.subscribe("_explorerTxs", payload, (e) => {
listener(e.detail);
});
}
//# sourceMappingURL=explorerTxs.js.map