@nktkas/hyperliquid
Version:
Hyperliquid API SDK for all major JS runtimes, written in TypeScript.
72 lines • 3.23 kB
JavaScript
import * as v from "valibot";
// ============================================================
// API Schemas
// ============================================================
import { Address } from "../../_schemas.js";
import { ClearinghouseStateResponse } from "./clearinghouseState.js";
import { SpotClearinghouseStateResponse } from "./spotClearinghouseState.js";
/**
* Request user sub-accounts.
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#retrieve-a-users-subaccounts
*/
export const SubAccountsRequest = /* @__PURE__ */ (() => {
return v.pipe(v.object({
/** Type of request. */
type: v.pipe(v.literal("subAccounts"), v.description("Type of request.")),
/** User address. */
user: v.pipe(Address, v.description("User address.")),
}), v.description("Request user sub-accounts."));
})();
/**
* Array of user sub-account or null if the user does not have any sub-accounts.
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#retrieve-a-users-subaccounts
*/
export const SubAccountsResponse = /* @__PURE__ */ (() => {
return v.pipe(v.nullable(v.array(v.object({
/** Sub-account name. */
name: v.pipe(v.string(), v.nonEmpty(), v.description("Sub-account name.")),
/** Sub-account address. */
subAccountUser: v.pipe(Address, v.description("Sub-account address.")),
/** Master account address. */
master: v.pipe(Address, v.description("Master account address.")),
/** Perpetual trading clearinghouse state summary. */
clearinghouseState: v.pipe(ClearinghouseStateResponse, v.description("Perpetual trading clearinghouse state summary.")),
/** Spot tokens clearinghouse state. */
spotState: v.pipe(SpotClearinghouseStateResponse, v.description("Spot tokens clearinghouse state.")),
}))), v.description("Array of user sub-account or null if the user does not have any sub-accounts."));
})();
/**
* Request user sub-accounts.
*
* @param config - General configuration for Info API requests.
* @param params - Parameters specific to the API request.
* @param signal - {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | AbortSignal} to cancel the request.
*
* @returns Array of user sub-account or null if the user does not have any sub-accounts.
*
* @throws {ValiError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
*
* @example
* ```ts
* import { HttpTransport } from "@nktkas/hyperliquid";
* import { subAccounts } from "@nktkas/hyperliquid/api/info";
*
* const transport = new HttpTransport(); // or `WebSocketTransport`
*
* const data = await subAccounts(
* { transport },
* { user: "0x..." },
* );
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#retrieve-a-users-subaccounts
*/
export function subAccounts(config, params, signal) {
const request = v.parse(SubAccountsRequest, {
type: "subAccounts",
...params,
});
return config.transport.request("info", request, signal);
}
//# sourceMappingURL=subAccounts.js.map