Hyperliquid API SDK: read sub-account DEX states with getSubAccountsWithAllDexStates
Published: December 5, 2026
A Hyperliquid master address can hold several sub-accounts, and each one can have balances on the default perp DEX and on named perp DEXes. The @siebly/hyperliquid-api SDK exposes getSubAccountsWithAllDexStates() on its RestClient. You pass a public master address and get those states, with no API key.
Install
npm install @siebly/hyperliquid-api
The script
The example uses a public master address and writes each sub-account, its DEX account values, and any non-zero spot balances.
import { RestClient } from '@siebly/hyperliquid-api';
const client = new RestClient();
const master = '0xd4c1f7e8d876c4749228d515473d36f919583d1d';
const short = (a) => a.slice(0, 6) + '...' + a.slice(-4);
const subs = await client.getSubAccountsWithAllDexStates({ user: master });
console.log('master', short(master));
console.log('count', subs ? subs.length : 0);
for (const row of subs ?? []) {
console.log(
'name',
row.name,
'sub',
short(row.subAccountUser),
'abstraction',
row.abstraction ?? 'default',
);
for (const [dex, state] of row.dexToClearinghouseState) {
const label = dex === '' ? '(default)' : dex;
const first = state.assetPositions[0]?.position;
console.log(
' dex',
label,
'accountValue',
state.marginSummary.accountValue,
'withdrawable',
state.withdrawable,
'positions',
state.assetPositions.length,
first ? `${first.coin} szi ${first.szi}` : '',
);
}
const spots = row.spotState.balances.filter((b) => Number(b.total) !== 0);
for (const bal of spots.slice(0, 3)) {
console.log(' spot', bal.coin, bal.total);
}
}
Example output
master 0xd4c1...3d1d
count 5
name xyz001 sub 0x1bcd...a684 abstraction disabled
name xyz002 sub 0x33b2...18dd abstraction disabled
dex xyz accountValue 10100.934905 withdrawable 10100.934905 positions 0
spot USDC 0.007334
name xyz003 sub 0x56f7...1560 abstraction disabled
dex (default) accountValue 13709.209971 withdrawable 13114.00668 positions 1 HYPE szi 104.31
dex xyz accountValue 0.01 withdrawable 0.01 positions 0
spot USDC 0.008994
name xyz004 sub 0x2d1a...6427 abstraction disabled
dex xyz accountValue 2213111.199337 withdrawable 1766418.744193 positions 13 xyz:NVDA szi -1643.488
spot USDC 0.00144
name d1001 sub 0x6da7...c2e9 abstraction disabled
dex (default) accountValue 57452.494358 withdrawable 56714.026839 positions 10 BTC szi -0.03535
spot USDC 100.0
This master has five sub-accounts. xyz004 holds the largest named-DEX account, with 13 positions, the first of which is xyz:NVDA. d1001 and xyz003 also have balances on the default perp DEX. An address with no sub-accounts returns null, not an empty array. The figures move a little from run to run.
The response shape
- The top-level result is an array of sub-accounts, or
null. - Each row has
name,master,subAccountUser, and an optionalabstractionfield (dexAbstraction,disabled,portfolioMargin, orunifiedAccount). When the field is omitted, the mode isdefault. dexToClearinghouseStateis a list of pairs. The first value is the DEX name (an empty string is the default perp DEX). The second value is the perp account summary for that DEX.marginSummary.accountValueis the account value on that DEX.withdrawableis the amount that can be withdrawn.assetPositionsis the open position list, which can be long, so the example prints only the first coin.spotState.balancesholds spot balances for the sub-account, withcoin,total, andhold.
Frequently raised questions
Does getSubAccountsWithAllDexStates need an API key?
No. Any public master address works with new RestClient(), which makes it a good fit for research and dashboards on the Hyperliquid API.
How is this different from getSubAccounts?
getSubAccounts returns the default perp clearinghouse state for each sub-account. getSubAccountsWithAllDexStates adds a state for every named perp DEX as well, so you can see HIP-3 balances in the same call. Use the latter when a sub-account may trade outside the default DEX.
Does it work on testnet, and does TypeScript work?
Yes to both. Create the client with { testnet: true }. Testnet sub-accounts are separate from mainnet. The package also ships TypeScript types for SubAccountWithAllDexStates and the nested account summary.
What if I pass a sub-account address instead of the master?
The method lists sub-accounts of a master. Passing a sub-account address, or a master with none, returns null. Query fills, positions, or orders for a sub-account with its own subAccountUser address.