Skip to main content
liquidationPrice(), pnl() and rolloverFee() are standalone functions over plain numbers — no client, no network. For bots, backtesters and risk dashboards. All three run @ostium/formulae, the same math the contracts use.

liquidationPrice

Accrued fees push the liquidation price toward the entry price, so a long-held position liquidates sooner than it did at open. Pass rollover for the current figure.

pnl

Returns netPnl (USDC, after rollover and funding), netPnlPercent (as a percentage of collateral) and netValue (collateral + netPnl — what the position is worth if closed now).

rolloverFee

Positive means the trader pays. Rollover accumulators are global per pair, not per position, so one getPairs() poll plus a block number lets you keep liquidation price and PnL current for any number of positions locally — no per-position read, and no re-fetching positions. createStore() does this for you.

maxWithdrawable / maxAddCollateral

The two collateral-edit limits, for a ticket that has to bound its own input.
Removing collateral raises leverage, so it is bounded by three limits at once and maxWithdrawable returns the smallest: the leverage cap, liquidation safety (accrued fees and unrealised loss), and profit protection. The leverage cap alone overstates the answer on a losing position — 900 in the example above. Adding collateral lowers leverage, so that direction is bounded by the pair group’s minimum, Pair.minLeverage. Position.maxWithdrawable is this number, already computed for an open position.