> 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/risk-monitoring-and-prop-firms.md). Agents can also search and read this documentation through its [MCP server](https://hydromancer.xyz/docs/~gitbook/mcp).

# Risk monitoring and prop firms

Watch many Hyperliquid trading accounts at once: equity, leverage, liquidation prices, deposits and withdrawals, and results.

Checking accounts one by one does not scale past a handful. The batch requests and many-address streams below let one service watch hundreds of accounts.

Prop firms, funds and risk teams usually need to:

* check the equity and positions of every account on a schedule
* enforce leverage and position rules
* get alerted on fills, deposits and withdrawals
* score each trader's results

**At a glance**

| What you need                         | Use                                                                                                                                                                                                                                                                                            |
| ------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Equity and positions for many wallets | [batchClearinghouseStates](https://docs.hydromancer.xyz/readme/rest-api/user-position-data/batchclearinghousestates)                                                                                                                                                                           |
| The same, with spot balances          | [batchPortfolioStates](https://docs.hydromancer.xyz/readme/rest-api/user-position-data/batchportfoliostates)                                                                                                                                                                                   |
| Sub-accounts of a trader              | [subAccounts](https://docs.hydromancer.xyz/readme/rest-api/subaccounts/subaccounts)                                                                                                                                                                                                            |
| Leverage and margin changes, live     | [userLeverageUpdates](https://docs.hydromancer.xyz/readme/websocket/leverage-and-margin-updates/userleverageupdates)                                                                                                                                                                           |
| Leverage and margin changes, history  | [userLeverageUpdatesByTime](https://docs.hydromancer.xyz/readme/rest-api/historical-data/userleverageupdatesbytime), [userIsolatedMarginUpdatesByTime](https://docs.hydromancer.xyz/readme/rest-api/historical-data/userisolatedmarginupdatesbytime)                                           |
| A trader's limits on one coin         | [activeAssetData](https://docs.hydromancer.xyz/readme/rest-api/user-position-data/activeassetdata)                                                                                                                                                                                             |
| Fills, orders and transfers, live     | [userFills](https://docs.hydromancer.xyz/readme/websocket/user-data/userfills), [userOrderUpdates](https://docs.hydromancer.xyz/readme/websocket/user-data/userorderupdates), [userNonFundingLedgerEvents](https://docs.hydromancer.xyz/readme/websocket/user-data/usernonfundingledgerevents) |
| Liquidations                          | [liquidationFills](https://docs.hydromancer.xyz/readme/websocket/trades-data/liquidationfills)                                                                                                                                                                                                 |
| Results                               | [userPnlSummary](https://docs.hydromancer.xyz/readme/rest-api/user-performance/userpnlsummary), [userCompletedTradesByTime](https://docs.hydromancer.xyz/readme/rest-api/user-performance/usercompletedtradesbytime)                                                                           |

**Account state for every trader**

[batchClearinghouseStates](https://docs.hydromancer.xyz/readme/rest-api/user-position-data/batchclearinghousestates) returns the perp state of up to 1,000 wallets per request, or 100 with `"dex": "ALL_DEXES"`.

The response has `successful_states`, a list of `[address, state]` pairs, and `failed_wallets`. Each state has a `marginSummary` (`accountValue`, `totalNtlPos`, `totalMarginUsed`), `crossMaintenanceMarginUsed`, `withdrawable` and the positions. Each position has `coin`, `szi`, `leverage`, `entryPx`, `positionValue`, `unrealizedPnl`, `liquidationPx` and `marginUsed`:

* `szi` is the signed size: negative for a short.
* `liquidationPx` can be `null`, so handle that case.
* With `ALL_DEXES`, each state is keyed by DEX (`native`, `xyz` and so on).
* Compare `crossMaintenanceMarginUsed` with `accountValue` to see how close a cross-margin account is to liquidation.

For unified account and portfolio margin wallets, use [batchPortfolioStates](https://docs.hydromancer.xyz/readme/rest-api/user-position-data/batchportfoliostates), which adds spot balances (500 wallets per request, 100 with `ALL_DEXES`). If traders use sub-accounts, [subAccounts](https://docs.hydromancer.xyz/readme/rest-api/subaccounts/subaccounts) returns each one with its own state.

**Leverage and margin rules**

The [userLeverageUpdates](https://docs.hydromancer.xyz/readme/websocket/leverage-and-margin-updates/userleverageupdates) stream reports changes for up to 1,000 addresses per subscription. The `update_type` tells you what changed:

* `leverage` - the user set a new leverage on a coin: `coin`, `leverage` and `is_cross`
* `isolated_margin` and `top_up_isolated_margin` - the margin of an isolated position changed: `coin` and the amount in `ntli`

[userLeverageUpdatesByTime](https://docs.hydromancer.xyz/readme/rest-api/historical-data/userleverageupdatesbytime) and [userIsolatedMarginUpdatesByTime](https://docs.hydromancer.xyz/readme/rest-api/historical-data/userisolatedmarginupdatesbytime) return the same events as history, oldest first.

[activeAssetData](https://docs.hydromancer.xyz/readme/rest-api/user-position-data/activeassetdata) shows a user's current leverage on one coin and the largest long and short they can open.

**Activity alerts**

[userFills](https://docs.hydromancer.xyz/readme/websocket/user-data/userfills), [userOrderUpdates](https://docs.hydromancer.xyz/readme/websocket/user-data/userorderupdates) and [userNonFundingLedgerEvents](https://docs.hydromancer.xyz/readme/websocket/user-data/usernonfundingledgerevents) each accept many addresses on one connection.

Use the ledger stream to catch deposits, withdrawals and transfers during an evaluation. Each event has an `eventType`, the `user`, the `counterparty`, the `amount` and a `role` of `sender` or `receiver`.

[liquidationFills](https://docs.hydromancer.xyz/readme/websocket/trades-data/liquidationfills) streams every liquidation on Hyperliquid.

When you reconnect with a session, replayed and live events can overlap. Skip fills you have already processed using `(time, txIndex)`, and ledger events using `(time, txIndex, role)`.

**Results**

[userPnlSummary](https://docs.hydromancer.xyz/readme/rest-api/user-performance/userpnlsummary) returns one trader's realized results: `totalPnl`, `winRate`, `totalTrades`, `volumeTraded`, `totalFees` and `totalFunding`. Add `startTime` and `endTime` to score one evaluation period.

[userCompletedTradesByTime](https://docs.hydromancer.xyz/readme/rest-api/user-performance/usercompletedtradesbytime) pages through closed positions by close time, oldest first. Each has entry and exit price, net PnL, fees, funding, duration, leverage and the largest size the position reached.

**Putting it together**

1. On a schedule, request `batchClearinghouseStates` for all accounts and check equity and margin against your rules.
2. Subscribe to `userLeverageUpdates`, `userFills` and `userNonFundingLedgerEvents` for the same addresses, to react between checks.
3. At the end of a period, score each account with `userPnlSummary` over that period.
