Skip to main content
Fetch account balances, positions, open orders, and trade history.
The examples on this page use Hyperliquid (dex: 'hyperliquid'). Replace the dex value with any supported DEX from getDexes().

getAccount

Returns the full account summary for a DEX including balances, positions, open orders, and fee tier.
import { getAccount } from '@lifi/perps-sdk';

const account = await getAccount(client, {
  dex: 'hyperliquid',
  address: userAddress,
});

console.log('Balance:', account.balances);
console.log('Margin used:', account.marginUsed);
console.log('Unrealized PnL:', account.unrealizedPnl);
console.log('Positions:', account.positions.length);
console.log('Open orders:', account.openOrders.length);

Parameters

ParameterTypeRequiredDescription
clientPerpsSDKClientYesSDK client from createPerpsClient()
params.dexstringYesDEX identifier
params.addressstringYesUser’s wallet address
optionsSDKRequestOptionsNoRequest options

Returns

AccountResponse:
FieldTypeDescription
dexstringDEX identifier
addressstringUser’s wallet address
balancesBalance[]Account balances by currency
marginUsedstringMargin currently in use
unrealizedPnlstringTotal unrealized PnL
feeTierFeeTierMaker and taker fee rates
positionsPosition[]Open positions
openOrdersOpenOrder[]Resting orders
configobjectDEX-specific account configuration (agent status, builder fee, etc.)

Position fields

FieldTypeDescription
symbolstringTrading symbol
assetIdnumberAsset ID
dexstringDEX identifier
side'LONG' | 'SHORT'Position direction
sizestringPosition size
entryPricestringAverage entry price
markPricestringCurrent mark price
liquidationPricestringEstimated liquidation price
unrealizedPnlstringUnrealized profit/loss
leveragenumberCurrent leverage
marginUsedstringMargin allocated
marginMode'ISOLATED' | 'CROSS'Margin mode

OpenOrder fields

FieldTypeDescription
idstringOrder ID
symbolstringTrading symbol
assetIdnumberAsset ID
dexstringDEX identifier
side'BUY' | 'SELL'Order direction
type'LIMIT' | 'MARKET'Order type
sizestringOrder size
pricestringLimit price
filledSizestringAmount filled
reduceOnlybooleanWhether reduce-only
createdAtstringISO 8601 timestamp
API Reference: GET /account

getHistory

Returns paginated historical orders. Results are sorted by creation time, newest first.
import { getHistory } from '@lifi/perps-sdk';

const history = await getHistory(client, {
  dex: 'hyperliquid',
  address: userAddress,
  limit: 50,
});

for (const item of history.items) {
  console.log(item.symbol, item.side, item.status, item.realizedPnl);
}

// Pagination
if (history.pagination.hasMore) {
  const nextPage = await getHistory(client, {
    dex: 'hyperliquid',
    address: userAddress,
    cursor: history.pagination.cursor,
  });
}

Parameters

ParameterTypeRequiredDescription
clientPerpsSDKClientYesSDK client
params.dexstringYesDEX identifier
params.addressstringYesUser’s wallet address
params.cursorstringNoPagination cursor from previous response
params.limitnumberNoItems per page (default 50, max 100)
params.startTimenumberNoFilter: orders after this timestamp (ms)
params.endTimenumberNoFilter: orders before this timestamp (ms)
optionsSDKRequestOptionsNoRequest options

Returns

HistoryResponse:
FieldTypeDescription
dexstringDEX identifier
itemsHistoryItem[]Historical orders
paginationPaginationPagination metadata

HistoryItem fields

FieldTypeDescription
idstringOrder ID
symbolstringTrading symbol
assetIdnumberAsset ID
dexstringDEX identifier
side'BUY' | 'SELL'Order direction
type'MARKET' | 'LIMIT'Order type
sizestringOriginal order size
pricestringOrder price
statusHistoryItemStatusFILLED, PARTIALLY_FILLED, CANCELLED, REJECTED (subset of OrderStatus — only terminal states appear in history)
filledSizestring?Amount filled (absent if no fills yet)
feestring?Total fees paid (absent if no fills yet)
realizedPnlstring | null?Realized PnL (present only when closing a position, null otherwise)
createdAtstringISO 8601 timestamp

Pagination fields

FieldTypeDescription
limitnumberItems per page
hasMorebooleanWhether more pages exist — use this as the authoritative check
cursorstring?Cursor for next page (pass to getHistory for the next page)
nextUrlstring?Full URL for next page (may be absent)
API Reference: GET /history