@nktkas/hyperliquid
Version:
Hyperliquid API SDK for all major JS runtimes, written in TypeScript.
74 lines • 3.11 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 V2.
*/
export const SubAccounts2Request = /* @__PURE__ */ (() => {
return v.pipe(v.object({
/** Type of request. */
type: v.pipe(v.literal("subAccounts2"), 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.
*/
export const SubAccounts2Response = /* @__PURE__ */ (() => {
return v.pipe(v.nullable(v.array(
/** Sub-account details for a user. */
v.pipe(v.object({
/** Sub-account name. */
name: v.pipe(v.string(), v.minLength(1), 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.")),
/** DEX to clearinghouse state mapping. Always includes the main DEX (empty dex name). */
dexToClearinghouseState: v.pipe(v.array(v.tuple([
v.string(),
ClearinghouseStateResponse,
])), v.minLength(1), v.description("DEX to clearinghouse state mapping. Always includes the main DEX (empty dex name).")),
/** Spot tokens clearinghouse state. */
spotState: SpotClearinghouseStateResponse,
}), v.description("Sub-account details for a user.")))), v.description("Array of user sub-account or null if the user does not have any sub-accounts."));
})();
/**
* Request user sub-accounts V2.
*
* @param config - General configuration for Info API requests.
* @param params - Parameters specific to the API request.
* @param signal - [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/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.
*
* @seenull
* @example
* ```ts
* import { HttpTransport } from "@nktkas/hyperliquid";
* import { subAccounts2 } from "@nktkas/hyperliquid/api/info";
*
* const transport = new HttpTransport(); // or `WebSocketTransport`
*
* const data = await subAccounts2(
* { transport },
* { user: "0x..." },
* );
* ```
*/
export function subAccounts2(config, params, signal) {
const request = v.parse(SubAccounts2Request, {
type: "subAccounts2",
...params,
});
return config.transport.request("info", request, signal);
}
//# sourceMappingURL=subAccounts2.js.map