Skip to content
markpaper

src/transport/types.ts

v0.3.0 · 1.2 KB

Download file
// Shared contract between modules. Modules that read from Hyperliquid take an
// InfoRequester instead of importing a concrete client, so every module can be
// tested with a stub and used with any transport (the kit's throttled client,
// a raw fetch, or an SDK InfoClient wrapped in a function).

export type Network = 'mainnet' | 'testnet';

export const API_URL: Record<Network, string> = {
  mainnet: 'https://api.hyperliquid.xyz',
  testnet: 'https://api.hyperliquid-testnet.xyz',
};

export const WS_URL: Record<Network, string> = {
  mainnet: 'wss://api.hyperliquid.xyz/ws',
  testnet: 'wss://api.hyperliquid-testnet.xyz/ws',
};

/** Body of a POST /info request: `{ type, ...params }`. */
export interface InfoRequest {
  type: string;
  [key: string]: unknown;
}

export interface InfoCallOptions {
  /** Request weight for the rate limiter; the client derives it from `type` when omitted. */
  weight?: number;
  /** Abort signal combined with the client's own timeout. */
  signal?: AbortSignal;
  /** Per-call timeout override in milliseconds. */
  timeoutMs?: number;
}

/** Performs one POST /info call and resolves with the parsed JSON body. */
export type InfoRequester = <T = unknown>(body: InfoRequest, opts?: InfoCallOptions) => Promise<T>;
All files