Prior Protocol / Docs
Exchange / Docs / Reference / API: perp.js

API: perp.js

Indices, funding, margin and collateral.

Import path site/perp.js. Imports options.js and nothing else.

Indices and funding

constantMaturityIndex(o)
kind of 'vol', 'call' or 'straddle'. Returns {value, unit, T, K}.
fundingRate(o)
{mark, index} to a rate per interval, damped and capped.
fundingPayment(o)
Signed payment for a position over one interval.

Marking and risk

markPortfolio(p, m)
Returns {value, legs, greeks}. Handles option, perp and spot legs.
shockGrid(o)
Derives the scenario grid from {atmVol, horizonDays, sigmas}.
stressPortfolio(p, m)
Full revaluation at every node. Returns the worst loss, the scenario that produced it, and every cell.
marginRequirement(p, m)
Initial and maintenance from the scenario loss.
borrowingPower(p, m)
Value less the haircut scenario loss, floored at zero, plus the advance rate.
accountHealth(o)
Equity over maintenance margin. Below 1.0 is liquidatable.
liquidationSpot(o)
Bisection for the spot at which the account becomes liquidatable, or null if it never does in that direction.

Position shapes

accepted legs
{ kind: 'call' | 'put', K, expiryDays, qty }
{ kind: 'perp', indexKind, tenorDays, qty, entry }
{ kind: 'spot', qty }

negative qty is short