Skip to main content
Use this page when you need account health, margin requirements, transferable collateral, or liquidation estimates after you have live trader state. For account setup and trader-state subscriptions across subaccounts, see Accounts.

Join Market Prices

For margin and account health, subscribe to trader state and market stats for positions, orders, and collateral pricing markets—even when there is no position in the collateral asset. Preserve spot collateral balances and update both mark and index prices. See Native SOL collateral for the required upgrade and deposit flow. The margin examples below fetch current market prices and collateral configuration from the API. For a live view, recompute after trader-state, price, funding, or collateral-configuration updates; a previous result is a snapshot, not a live calculator.

Local Margin

Use trader-state marginInputs() and market params to compute local margin. For real-time monitoring, update market prices from WebSocket streams before recomputing.
Reference: Rust live margin example.

Cache-Backed Liquidation Estimates (Quote Collateral Only)

For fast UI updates and risk monitoring, estimate liquidation prices from local trader state plus the exchange cache. This avoids API polling and uses the same SDK margin primitives described above. These custom examples support quote-only collateral. They reject spot collateral instead of omitting its value. For SOL-backed accounts, use the SDK margin flow above and Hawkeye simulation for liquidation prices. The examples below binary-search the mark price where the subaccount risk tier crosses into liquidatable or worse. This keeps the estimate tied to SDK margin math, leverage tiers, funding, discounted uPnL, and limit-order margin. Treat it as a local estimate: stream freshness and search bounds matter. Use Hawkeye for the authoritative on-chain simulation. In TypeScript, the flow is client.exchange.ready(), client.exchange.market(symbol), client.marketData().market(symbol), resource.marginInputs(), then createMarginCalculator(...). In Rust, the flow is PhoenixMetadata::apply_market_stats(&stats), Trader::apply_update(&msg), SubaccountState::to_trader_portfolio(), then TraderPortfolio::compute_margin(metadata.all_perp_asset_metadata()).
This estimate depends on the same cache freshness as margin monitoring. In TypeScript, keep client.exchange and client.marketData() live. In Rust, keep applying PhoenixMetadata::apply_market_stats(&stats) and trader-state updates before recomputing.

Hawkeye Simulation

For an authoritative liquidation-price view, use Hawkeye simulation through the SDK. This runs a read-only simulation and decodes the program return data.

Isolated Order Estimates

Server-built isolated order routes can also return the post-trade isolated liquidation estimate.