@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
| Property | Type | Description |
|---|---|---|
client.auth | AuthService | SIWE nonce + verify, dev-login |
client.orders | OrdersService | Submit, cancel, list, get orders |
client.markets | MarketsService | List markets |
client.positions | PositionsService | List open positions |
client.accounts | AccountsRestService | Register + get account |
client.sse | SSEService | Subscribe to real-time event channels |
client.relay | RelayService | Gasless relay: submit a signed batch, poll its job |
Other exports
AuthService,AuthTokens— standalone auth service + token typeOrdersService— order CRUDMarketsService— market listPositionsService,GatewayPosition(whatlist/getOnereturn: signedsize,sidederived from it,realizedPnl, andepisodeRealizedPnl/episodeFeesUsd— the current position's price PnL and fees,nullwhen unknown),PositionResponse(the raw wire row) — positionsAccountsRestService,RegisterAccountParams,RegisterAccountResponse— account managementSSEService,SSEEventHandler— SSE subscription helpersLiqApiError— typed API error (status code + error code + body)
Install
pnpm add @liq/api-client
Dependencies
@liq/core— shared types and enumsup-fetch— lightweight fetch wrapper with base URL + interceptors
Build
moon run liq-api-client:build # tsup → dist/