@nktkas/hyperliquid
Version:
Hyperliquid API SDK for all major JS runtimes, written in TypeScript.
109 lines (108 loc) • 4.25 kB
TypeScript
/// <amd-module name="file:///home/runner/work/hyperliquid/hyperliquid/src/api/info/_methods/webData2.ts" />
import * as v from "valibot";
import type { PerpAssetCtx, SpotAssetCtx, TwapState } from "./_base/mod.js";
import type { ClearinghouseStateResponse } from "./clearinghouseState.js";
import type { FrontendOpenOrdersResponse } from "./frontendOpenOrders.js";
import type { LeadingVaultsResponse } from "./leadingVaults.js";
import type { MetaResponse } from "./meta.js";
import type { PerpsAtOpenInterestCapResponse } from "./perpsAtOpenInterestCap.js";
import type { SpotClearinghouseStateResponse } from "./spotClearinghouseState.js";
/**
* Request comprehensive user and market data.
* @see null
*/
export declare const WebData2Request: v.ObjectSchema<{
/** Type of request. */
readonly type: v.LiteralSchema<"webData2", undefined>;
/** User address. */
readonly user: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>, v.TransformAction<string, `0x${string}`>]>, v.LengthAction<`0x${string}`, 42, undefined>]>;
}, undefined>;
export type WebData2Request = v.InferOutput<typeof WebData2Request>;
/**
* Comprehensive user and market data.
* @see null
*/
export type WebData2Response = {
/** Account summary for perpetual trading. */
clearinghouseState: ClearinghouseStateResponse;
/** Array of leading vaults for a user. */
leadingVaults: LeadingVaultsResponse;
/**
* Total equity in vaults.
* @pattern ^[0-9]+(\.[0-9]+)?$
*/
totalVaultEquity: string;
/** Array of open orders with additional display information. */
openOrders: FrontendOpenOrdersResponse;
/**
* Agent address if one exists.
* @pattern ^0x[a-fA-F0-9]{40}$
*/
agentAddress: `0x${string}` | null;
/** Timestamp until which the agent is valid (in ms since epoch). */
agentValidUntil: number | null;
/**
* Cumulative ledger value.
* @pattern ^[0-9]+(\.[0-9]+)?$
*/
cumLedger: string;
/** Metadata for perpetual assets. */
meta: MetaResponse;
/** Array of contexts for each perpetual asset. */
assetCtxs: PerpAssetCtx[];
/** Server timestamp (in ms since epoch). */
serverTime: number;
/** Whether this account is a vault. */
isVault: boolean;
/**
* User address.
* @pattern ^0x[a-fA-F0-9]{40}$
*/
user: `0x${string}`;
/** Array of tuples containing TWAP order ID and its state. */
twapStates: [
/** ID of the TWAP. */
id: number,
/** TWAP order state. */
state: TwapState
][];
/** Account summary for spot trading. */
spotState?: SpotClearinghouseStateResponse;
/** Asset context for each spot asset. */
spotAssetCtxs: SpotAssetCtx[];
/** Whether the user has opted out of spot dusting. */
optOutOfSpotDusting?: true;
/** Assets currently at their open interest cap. */
perpsAtOpenInterestCap?: PerpsAtOpenInterestCapResponse;
};
import type { InfoConfig } from "./_base/mod.js";
/** Request parameters for the {@linkcode webData2} function. */
export type WebData2Parameters = Omit<v.InferInput<typeof WebData2Request>, "type">;
/**
* Request comprehensive user and market data.
*
* @deprecated use `webData3` and other component subscriptions instead.
*
* @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.
* @return Comprehensive user and market data.
*
* @throws {ValidationError} 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 { webData2 } from "@nktkas/hyperliquid/api/info";
*
* const transport = new HttpTransport(); // or `WebSocketTransport`
*
* const data = await webData2({ transport }, {
* user: "0x...",
* });
* ```
*
* @see null
*/
export declare function webData2(config: InfoConfig, params: WebData2Parameters, signal?: AbortSignal): Promise<WebData2Response>;