> For the complete documentation index, see [llms.txt](https://hydromancer.xyz/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hydromancer.xyz/docs/builder-guides/portfolio-trackers-and-wallets.md). Agents can also search and read this documentation through its [MCP server](https://hydromancer.xyz/docs/~gitbook/mcp).

# Portfolio trackers and wallets

Show a wallet's whole Hyperliquid account: balances, positions, orders, vaults, staking and lending, with live updates.

One wallet can hold perp positions on several DEXes, spot balances, vault deposits, staked HYPE, lending positions and sub-accounts. The requests below cover each part, so the total you show matches what the user owns.

Portfolio trackers and wallet apps usually need to:

* show perp positions and spot balances across every DEX
* list open orders
* include funds held in vaults, staking, lending and sub-accounts
* show history and performance
* update the screen as things happen

**At a glance**

| What you need                              | Use                                                                                                                                                                                                                                                                                                               |
| ------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Perp state, spot balances and account mode | [portfolioState](https://docs.hydromancer.xyz/readme/rest-api/user-position-data/portfoliostate)                                                                                                                                                                                                                  |
| The same for many wallets                  | [batchPortfolioStates](https://docs.hydromancer.xyz/readme/rest-api/user-position-data/batchportfoliostates)                                                                                                                                                                                                      |
| Open orders                                | [frontendOpenOrders](https://docs.hydromancer.xyz/readme/rest-api/user-order-data/frontendopenorders), [openOrders](https://docs.hydromancer.xyz/readme/rest-api/user-order-data/openorders)                                                                                                                      |
| Vault deposits                             | [userVaultEquities](https://docs.hydromancer.xyz/readme/rest-api/vaults/uservaultequities)                                                                                                                                                                                                                        |
| Staked HYPE                                | [delegatorSummary](https://docs.hydromancer.xyz/readme/rest-api/delegations/delegatorsummary), [delegations](https://docs.hydromancer.xyz/readme/rest-api/delegations/delegations)                                                                                                                                |
| Lending position                           | [borrowLendUserState](https://docs.hydromancer.xyz/readme/rest-api/borrow-lend/borrowlenduserstate)                                                                                                                                                                                                               |
| Sub-accounts                               | [subAccounts](https://docs.hydromancer.xyz/readme/rest-api/subaccounts/subaccounts)                                                                                                                                                                                                                               |
| Trades, funding and transfers              | [userFillsByTime](https://docs.hydromancer.xyz/readme/rest-api/historical-data/userfillsbytime), [userFunding](https://docs.hydromancer.xyz/readme/rest-api/historical-data/userfunding), [userNonFundingLedgerUpdates](https://docs.hydromancer.xyz/readme/rest-api/historical-data/usernonfundingledgerupdates) |
| Realized PnL                               | [userCompletedTrades](https://docs.hydromancer.xyz/readme/rest-api/user-performance/usercompletedtrades), [userPnlSummary](https://docs.hydromancer.xyz/readme/rest-api/user-performance/userpnlsummary)                                                                                                          |
| Fee rates                                  | [userFees](https://docs.hydromancer.xyz/readme/rest-api/fees/userfees)                                                                                                                                                                                                                                            |
| Live fills and transfers                   | [userFills](https://docs.hydromancer.xyz/readme/websocket/user-data/userfills), [userNonFundingLedgerEvents](https://docs.hydromancer.xyz/readme/websocket/user-data/usernonfundingledgerevents)                                                                                                                  |

**Balances and positions in one request**

[portfolioState](https://docs.hydromancer.xyz/readme/rest-api/user-position-data/portfoliostate) returns a wallet's perp state, spot balances and account mode together. Set `dex` to `"ALL_DEXES"` to include HIP-3 positions.

The response has three parts: `clearinghouseState` (perps), `spotClearinghouseState` (spot balances) and `userAbstraction` (account mode).

* With `ALL_DEXES`, `clearinghouseState` is keyed by DEX: `native` for Hyperliquid's own perps, then one entry per HIP-3 DEX such as `xyz`.
* Each DEX entry has a `marginSummary` (`accountValue`, `totalNtlPos`, `totalMarginUsed`), the `withdrawable` amount and the `assetPositions`.
* Each entry in `assetPositions` has the position's `szi` (negative for a short), `entryPx`, `positionValue`, `unrealizedPnl`, `liquidationPx`, `marginUsed` and `leverage`.
* Each spot balance has `coin`, `total` and `hold`.
* `userAbstraction` is the account mode: `unifiedAccount`, `portfolioMargin`, `disabled`, `default`, or the legacy `dexAbstraction`.

Read the spot balances as well as the perp state. Unified account and portfolio margin wallets keep their money in spot balances, so the perp state alone shows only part of it.

For many wallets, [batchPortfolioStates](https://docs.hydromancer.xyz/readme/rest-api/user-position-data/batchportfoliostates) takes 500 users per request, or 100 with `ALL_DEXES`. Check `failed_wallets` before treating a batch as complete.

**Open orders**

[frontendOpenOrders](https://docs.hydromancer.xyz/readme/rest-api/user-order-data/frontendopenorders) returns each open order with its `orderType` (`Limit`, `Stop Market`, `Take Profit Market` and so on), `triggerCondition`, `reduceOnly` and `isPositionTpsl`, so take profit and stop loss orders display correctly. [openOrders](https://docs.hydromancer.xyz/readme/rest-api/user-order-data/openorders) returns the plain list: coin, side, price, size and order ID.

**Vaults, staking, lending and sub-accounts**

* [userVaultEquities](https://docs.hydromancer.xyz/readme/rest-api/vaults/uservaultequities) - one row per vault: `vaultAddress`, `equity` and `lockedUntilTimestamp`
* [delegatorSummary](https://docs.hydromancer.xyz/readme/rest-api/delegations/delegatorsummary) - staked HYPE in total: `delegated`, `undelegated` and `totalPendingWithdrawal`. [delegations](https://docs.hydromancer.xyz/readme/rest-api/delegations/delegations) splits it by validator
* [borrowLendUserState](https://docs.hydromancer.xyz/readme/rest-api/borrow-lend/borrowlenduserstate) - supplied and borrowed amounts per token, and the account's `health`
* [subAccounts](https://docs.hydromancer.xyz/readme/rest-api/subaccounts/subaccounts) - each sub-account's `name` and address with its own perp and spot state. It returns `null` for a wallet with no sub-accounts

**History and performance**

Use [userFillsByTime](https://docs.hydromancer.xyz/readme/rest-api/historical-data/userfillsbytime) for trades, [userFunding](https://docs.hydromancer.xyz/readme/rest-api/historical-data/userfunding) for funding payments and [userNonFundingLedgerUpdates](https://docs.hydromancer.xyz/readme/rest-api/historical-data/usernonfundingledgerupdates) for deposits, withdrawals and transfers. To go further back in fills, page through `userFillsByTime` with its `cursor`.

[userCompletedTrades](https://docs.hydromancer.xyz/readme/rest-api/user-performance/usercompletedtrades) returns closed positions, each with entry and exit price, net PnL, fees, funding and duration. [userPnlSummary](https://docs.hydromancer.xyz/readme/rest-api/user-performance/userpnlsummary) rolls them into one response: total PnL, win rate, volume, fees and funding. Add `startTime` and `endTime` to scope it to a period.

[userFees](https://docs.hydromancer.xyz/readme/rest-api/fees/userfees) returns the user's current taker (`userCrossRate`) and maker (`userAddRate`) rates, any active referral or staking discount, and daily volume.

**Live updates**

The [userFills](https://docs.hydromancer.xyz/readme/websocket/user-data/userfills) and [userNonFundingLedgerEvents](https://docs.hydromancer.xyz/readme/websocket/user-data/usernonfundingledgerevents) streams accept many addresses on one connection, so one subscription covers every wallet a user tracks. `userFills` takes up to 1,000 addresses per subscription and delivers each fill as an `[address, fill]` pair.

Every message carries a `cursor`. Store it, and send it when you reconnect to receive what you missed. See [Session Management and Reconnection](https://docs.hydromancer.xyz/readme/websocket/session-management-and-reconnection).

**Putting it together**

1. Load the account with `portfolioState` using `ALL_DEXES`.
2. Add vault, staking, lending and sub-account balances from their own requests.
3. Subscribe to `userFills` and `userNonFundingLedgerEvents` for the wallet.
4. When an event arrives, refresh `portfolioState` for that wallet.
