@nktkas/hyperliquid
Version:
Hyperliquid API SDK for all major JS runtimes, written in TypeScript.
107 lines (106 loc) • 3.75 kB
TypeScript
/// <amd-module name="file:///home/runner/work/hyperliquid/hyperliquid/src/api/info/_methods/activeAssetData.ts" />
import * as v from "valibot";
/**
* Request user active asset data.
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-users-active-asset-data
*/
export declare const ActiveAssetDataRequest: v.ObjectSchema<{
/** Type of request. */
readonly type: v.LiteralSchema<"activeAssetData", undefined>;
/** Asset symbol (e.g., BTC). */
readonly coin: v.StringSchema<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 ActiveAssetDataRequest = v.InferOutput<typeof ActiveAssetDataRequest>;
/**
* User active asset data.
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-users-active-asset-data
*/
export type ActiveAssetDataResponse = {
/**
* User address.
* @pattern ^0x[a-fA-F0-9]{40}$
*/
user: `0x${string}`;
/** Asset symbol (e.g., BTC). */
coin: string;
/** Leverage configuration. */
leverage: {
/** Leverage type. */
type: "isolated";
/** Leverage value used. */
value: number;
/**
* Amount of USD used (1 = $1).
* @pattern ^-?[0-9]+(\.[0-9]+)?$
*/
rawUsd: string;
} | {
/** Leverage type. */
type: "cross";
/** Leverage value used. */
value: number;
};
/** Maximum trade size range [min, max]. */
maxTradeSzs: [
/**
* Minimum trade size.
* @pattern ^[0-9]+(\.[0-9]+)?$
*/
min: string,
/**
* Maximum trade size.
* @pattern ^[0-9]+(\.[0-9]+)?$
*/
max: string
];
/** Available to trade range [min, max]. */
availableToTrade: [
/**
* Minimum available to trade.
* @pattern ^[0-9]+(\.[0-9]+)?$
*/
min: string,
/**
* Maximum available to trade.
* @pattern ^[0-9]+(\.[0-9]+)?$
*/
max: string
];
/**
* Mark price.
* @pattern ^[0-9]+(\.[0-9]+)?$
*/
markPx: string;
};
import type { InfoConfig } from "./_base/mod.js";
/** Request parameters for the {@linkcode activeAssetData} function. */
export type ActiveAssetDataParameters = Omit<v.InferInput<typeof ActiveAssetDataRequest>, "type">;
/**
* Request user active asset data.
*
* @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 User active asset 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 { activeAssetData } from "@nktkas/hyperliquid/api/info";
*
* const transport = new HttpTransport(); // or `WebSocketTransport`
*
* const data = await activeAssetData({ transport }, {
* user: "0x...",
* coin: "ETH",
* });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-users-active-asset-data
*/
export declare function activeAssetData(config: InfoConfig, params: ActiveAssetDataParameters, signal?: AbortSignal): Promise<ActiveAssetDataResponse>;