Fetch DEX information, market details, prices, OHLCV chart data, and orderbook snapshots.
All service functions require a client as the first argument. Create one with createPerpsClient():
import { createPerpsClient } from '@lifi/perps-sdk';
const client = createPerpsClient({ integrator: 'my-app' });
The examples on this page use Hyperliquid (dex: 'hyperliquid'). Replace the dex value with any supported DEX from getDexes().
getDexes
Returns all available perpetual DEX platforms, including their authorization requirements.
import { getDexes } from '@lifi/perps-sdk';
const { dexes } = await getDexes(client);
for (const dex of dexes) {
console.log(dex.key, dex.name, dex.authorizations.length);
}
// hyperliquid Hyperliquid 2
Parameters
| Parameter | Type | Required | Description |
|---|
client | PerpsSDKClient | Yes | SDK client from createPerpsClient() |
options | SDKRequestOptions | No | Request options (e.g., signal for cancellation) |
Returns
DexesResponse — { dexes: Dex[] }:
| Field | Type | Description |
|---|
dexes | Dex[] | Array of DEX objects |
Each Dex:
| Field | Type | Description |
|---|
key | string | Unique DEX identifier (used in query params) |
name | string | Display name |
logoURI | string | URL to DEX logo image |
authorizations | Authorization[] | Available authorizations for this DEX |
wsUrl | string? | WebSocket endpoint for streaming (see Streaming) |
extraData | object? | DEX-specific extra data (sub-exchanges, feature flags, etc.) |
Each Authorization object:
| Field | Type | Description |
|---|
key | string | Authorization identifier (DEX-specific, e.g., ApproveAgent for Hyperliquid) |
name | string | Human-readable name |
params | AuthorizationParam[] | Required parameters |
Use dex.authorizations to dynamically build the authorization UI. See Authorization for the full flow.
API Reference: GET /dexes
getMarkets
Returns all perpetual markets for a specified DEX with funding rates, open interest, and volume.
import { getMarkets } from '@lifi/perps-sdk';
const { markets } = await getMarkets(client, { dex: 'hyperliquid' });
for (const market of markets) {
console.log(market.symbol, market.markPrice, `${market.maxLeverage}x`);
}
// BTC 95000.50 50x
// ETH 3200.25 50x
Parameters
| Parameter | Type | Required | Description |
|---|
client | PerpsSDKClient | Yes | SDK client |
params.dex | string | Yes | DEX identifier |
options | SDKRequestOptions | No | Request options |
Returns
MarketsResponse — { markets: Market[] }:
| Field | Type | Description |
|---|
markets | Market[] | Array of market objects |
Each Market:
| Field | Type | Description |
|---|
symbol | string | Trading symbol (e.g., BTC) |
name | string | Full asset name (e.g., Bitcoin) |
logoURI | string | URL to asset logo |
assetId | number | Asset ID (0-99 for main assets, 100000+ for xyz) |
dex | string | DEX identifier |
szDecimals | number | Size decimal places |
maxLeverage | number | Maximum allowed leverage |
onlyIsolated | boolean | Whether only isolated margin is supported |
funding | FundingInfo | Current funding rate and next funding time |
openInterest | string? | Total open interest in USD (may be absent for new markets) |
volume24h | string? | 24-hour trading volume in USD (may be absent for new markets) |
markPrice | string | Current mark price |
API Reference: GET /markets
getMarket
Returns details for a single market.
import { getMarket } from '@lifi/perps-sdk';
const btc = await getMarket(client, { dex: 'hyperliquid', symbol: 'BTC' });
console.log(btc.markPrice, btc.funding.rate);
// 95000.50 0.0001
Parameters
| Parameter | Type | Required | Description |
|---|
client | PerpsSDKClient | Yes | SDK client |
params.dex | string | Yes | DEX identifier |
params.symbol | string | Yes | Market symbol (e.g., BTC) |
options | SDKRequestOptions | No | Request options |
Returns
Market — Single market object (same shape as above).
API Reference: GET /markets/
getPrices
Returns current mid prices for all markets. Lightweight endpoint for frequent polling.
import { getPrices } from '@lifi/perps-sdk';
const { prices } = await getPrices(client, { dex: 'hyperliquid' });
console.log(prices);
// { BTC: '95000.50', ETH: '3200.25', SOL: '185.75' }
Parameters
| Parameter | Type | Required | Description |
|---|
client | PerpsSDKClient | Yes | SDK client |
params.dex | string | Yes | DEX identifier |
params.symbols | string[] | No | Filter to specific symbols |
options | SDKRequestOptions | No | Request options |
Returns
PricesResponse — { prices: Record<string, string> }:
| Field | Type | Description |
|---|
prices | Record<string, string> | Map of symbol to mid price |
API Reference: GET /prices
getOhlcv
Returns OHLCV candle data for charts.
import { getOhlcv } from '@lifi/perps-sdk';
const { candles } = await getOhlcv(client, {
dex: 'hyperliquid',
symbol: 'BTC',
interval: '1h',
limit: 100,
});
for (const candle of candles) {
console.log(candle.t, candle.o, candle.h, candle.l, candle.c, candle.v);
}
Parameters
| Parameter | Type | Required | Description |
|---|
client | PerpsSDKClient | Yes | SDK client |
params.dex | string | Yes | DEX identifier |
params.symbol | string | Yes | Market symbol |
params.interval | string | Yes | Candle interval: 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 8h, 12h, 1d, 3d, 1w, 1M |
params.startTime | number | No | Start timestamp in milliseconds |
params.endTime | number | No | End timestamp in milliseconds |
params.limit | number | No | Max candles to return (default 100, max 1000) |
options | SDKRequestOptions | No | Request options |
Returns
OhlcvResponse:
| Field | Type | Description |
|---|
dex | string | DEX identifier |
symbol | string | Market symbol |
interval | string | Candle interval |
candles | Candle[] | Array of candle data |
Each Candle:
| Field | Type | Description |
|---|
t | number | Timestamp in milliseconds |
o | string | Open price |
h | string | High price |
l | string | Low price |
c | string | Close price |
v | string | Volume |
API Reference: GET /ohlcv/
getOrderbook
Returns current orderbook snapshot with bids and asks.
import { getOrderbook } from '@lifi/perps-sdk';
const book = await getOrderbook(client, {
dex: 'hyperliquid',
symbol: 'BTC',
depth: 20,
});
console.log('Best bid:', book.bids[0].price, book.bids[0].size);
console.log('Best ask:', book.asks[0].price, book.asks[0].size);
Parameters
| Parameter | Type | Required | Description |
|---|
client | PerpsSDKClient | Yes | SDK client |
params.dex | string | Yes | DEX identifier |
params.symbol | string | Yes | Market symbol |
params.depth | number | No | Number of price levels (default 20, max 100) |
options | SDKRequestOptions | No | Request options |
Returns
OrderbookResponse:
| Field | Type | Description |
|---|
dex | string | DEX identifier |
symbol | string | Market symbol |
bids | OrderbookLevel[] | Bid price levels (descending) |
asks | OrderbookLevel[] | Ask price levels (ascending) |
timestamp | number | Snapshot timestamp in milliseconds |
Each OrderbookLevel:
| Field | Type | Description |
|---|
price | string | Price level |
size | string | Size at this price level |
API Reference: GET /orderbook/