UNPKG

@nktkas/hyperliquid

Version:

Hyperliquid API SDK for all major JS runtimes, written in TypeScript.

87 lines 3.78 kB
import { TransportError } from "../../_errors.js"; /** Error thrown when an HTTP request fails. */ export declare class HttpRequestError extends TransportError { /** The HTTP response that caused the error. */ response?: Response; /** The response body text. */ body?: string; /** * Creates a new HTTP request error. * @param args - The error arguments. * @param args.response - The HTTP response that caused the error. * @param args.body - The response body text. * @param options - The error options. */ constructor(args?: { response?: Response; body?: string; }, options?: ErrorOptions); } /** Configuration options for the HTTP transport layer. */ export interface HttpTransportOptions { /** * Indicates this transport uses testnet endpoint. * @default false */ isTestnet?: boolean; /** * Request timeout in ms. Set to `null` to disable. * @default 10_000 */ timeout?: number | null; /** * Custom API URL for requests. * @default `https://api.hyperliquid.xyz` for mainnet, `https://api.hyperliquid-testnet.xyz` for testnet. */ apiUrl?: string | URL; /** * Custom RPC URL for explorer requests. * @default `https://rpc.hyperliquid.xyz` for mainnet, `https://rpc.hyperliquid-testnet.xyz` for testnet. */ rpcUrl?: string | URL; /** A custom [`RequestInit`](https://developer.mozilla.org/en-US/docs/Web/API/RequestInit) that is merged with a fetch request. */ fetchOptions?: Omit<RequestInit, "body" | "method">; } /** Mainnet API URL. */ export declare const MAINNET_API_URL = "https://api.hyperliquid.xyz"; /** Testnet API URL. */ export declare const TESTNET_API_URL = "https://api.hyperliquid-testnet.xyz"; /** Mainnet RPC URL. */ export declare const MAINNET_RPC_URL = "https://rpc.hyperliquid.xyz"; /** Testnet RPC URL. */ export declare const TESTNET_RPC_URL = "https://rpc.hyperliquid-testnet.xyz"; /** * HTTP transport for Hyperliquid API. * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint */ export declare class HttpTransport implements HttpTransportOptions { isTestnet: boolean; timeout: number | null; apiUrl: string | URL; rpcUrl: string | URL; fetchOptions: Omit<RequestInit, "body" | "method">; /** * Creates a new HTTP transport instance. * @param options - Configuration options for the HTTP transport layer. */ constructor(options?: HttpTransportOptions); /** * Sends a request to the Hyperliquid API via [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API). * * @param endpoint - The API endpoint to send the request to. * @param payload - The payload to send with the request. * @param signal - [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) to cancel the request. * * @returns A promise that resolves with parsed JSON response body. * * @throws {HttpRequestError} Thrown when the HTTP request fails. */ request<T>(endpoint: "info" | "exchange" | "explorer", payload: unknown, signal?: AbortSignal): Promise<T>; /** Merges multiple `HeadersInit` into one [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/Headers). */ protected _mergeHeadersInit(...inits: HeadersInit[]): Headers; /** Merges multiple [`RequestInit`](https://developer.mozilla.org/en-US/docs/Web/API/RequestInit) into one [`RequestInit`](https://developer.mozilla.org/en-US/docs/Web/API/RequestInit). */ protected _mergeRequestInit(...inits: RequestInit[]): RequestInit; } //# sourceMappingURL=mod.d.ts.map