@liqpro/liq-api-client

中文文档
0.83.0发布于 2026/11/02TypeScriptES Module

Typed REST + SSE client for the Liq order-gateway API.

原始使用文档
文档目录7 节
  1. Overview
  2. Key Exports
  3. LiqClient
  4. Other exports
  5. Install
  6. Dependencies
  7. Build

@liq/api-client

Typed REST + SSE client for the Liq order-gateway API.

Overview

@liq/api-client provides a typed HTTP client for interacting with the order-gateway service. It wraps up-fetch with automatic JWT bearer token management, response envelope unwrapping ({ data: T } → T), and structured error handling via LiqApiError. Responses are typed but not validated at runtime (one client build reads several gateway versions), so a payload that drifted from the declared type reaches the caller as is. The top-level LiqClient exposes namespaced service objects for auth, orders, markets, positions, accounts, and SSE streaming.

Key Exports

LiqClient

Main entry point. Constructed with { baseUrl, chainId? }.

const client = new LiqClient({ baseUrl: 'http://localhost:4000/v1' });
client.setToken(jwt); // set or clear auth token
PropertyTypeDescription
client.authAuthServiceSIWE nonce + verify, dev-login
client.ordersOrdersServiceSubmit, cancel, list, get orders
client.marketsMarketsServiceList markets
client.positionsPositionsServiceList open positions
client.accountsAccountsRestServiceRegister + get account
client.sseSSEServiceSubscribe to real-time event channels
client.relayRelayServiceGasless relay: submit a signed batch, poll its job

Other exports

  • AuthService, AuthTokens — standalone auth service + token type
  • OrdersService — order CRUD
  • MarketsService — market list
  • PositionsService, GatewayPosition (what list / getOne return: signed size, side derived from it, realizedPnl, and episodeRealizedPnl / episodeFeesUsd — the current position's price PnL and fees, null when unknown), PositionResponse (the raw wire row) — positions
  • AccountsRestService, RegisterAccountParams, RegisterAccountResponse — account management
  • SSEService, SSEEventHandler — SSE subscription helpers
  • LiqApiError — typed API error (status code + error code + body)

Install

pnpm add @liq/api-client

Dependencies

  • @liq/core — shared types and enums
  • up-fetch — lightweight fetch wrapper with base URL + interceptors

Build

moon run liq-api-client:build    # tsup → dist/

版本与发布记录

@liqpro/liq-api-client 共发布 53 个版本,首次发布于 2026/06/14;过去 12 个月发布了 53 个版本。

版本发布日期距今
0.83.0latest2026/11/021 天前
0.80.02026/10/295 天前
0.79.02026/10/277 天前
0.78.02026/10/2410 天前
0.77.02026/10/2410 天前
0.74.02026/10/2113 天前

关于 @liqpro/liq-api-client 的常见问题

@liqpro/liq-api-client 是什么?

Liq订单网关API的类型REST + SSE客户端。

如何安装 @liqpro/liq-api-client?

在项目目录运行 npm install @liqpro/liq-api-client,或使用 pnpm add / yarn add / bun add。

@liqpro/liq-api-client 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@liqpro/liq-api-client 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@liqpro/liq-api-client 可以商用吗?

@liqpro/liq-api-client 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@liqpro/liq-api-client 还在维护吗?

最新版本 0.83.0 发布于 2026/11/02(1 天前);至今共发布 53 个版本,其中过去 12 个月发布了 53 个;首次发布于 2026/06/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。