@somnia-chain/markets-sdk / index / PerpClosePreview
Type Alias: PerpClosePreview
PerpClosePreview = {
priceable:false;asOfBlock:bigint; } | {priceable:true;asOfBlock:bigint;requestedQuantity:bigint;closedQuantity:bigint;remainingSize:bigint;fullClose:boolean;realizedPnl:bigint;fundingSettled:bigint;fee:bigint;netProceeds:bigint;placeable:boolean;fillPrice:bigint;markPrice:bigint;avgEntryPrice:bigint;lotSize:bigint;minQuantity:bigint; }
Defined in: packages/sdk/src/perp/margin.ts:2807
What closing part or all of a position would realise.
Union Members
Type Literal
{ priceable: false; asOfBlock: bigint; }
priceable
priceable:
false
The pool's mark feed is stale or zero, so nothing can be marked.
asOfBlock
asOfBlock:
bigint
The block every read was pinned to.
Type Literal
{ priceable: true; asOfBlock: bigint; requestedQuantity: bigint; closedQuantity: bigint; remainingSize: bigint; fullClose: boolean; realizedPnl: bigint; fundingSettled: bigint; fee: bigint; netProceeds: bigint; placeable: boolean; fillPrice: bigint; markPrice: bigint; avgEntryPrice: bigint; lotSize: bigint; minQuantity: bigint; }
priceable
priceable:
true
asOfBlock
asOfBlock:
bigint
The block every read was pinned to.
requestedQuantity
requestedQuantity:
bigint
What the caller asked to close, raw base units — already normalised.
An omitted quantity or a 0n one means "all", and both arrive here as
|size| rather than 0n, so an "all" request is not distinguishable from an
explicit full-size one on the way out. Compare against closedQuantity
to see what the lot grid took off.
closedQuantity
closedQuantity:
bigint
What would ACTUALLY close: clamped to the position, then aligned down to the pool's lot grid.
Below requestedQuantity whenever the position is not a lot multiple, which is what leaves a remainder open on a "close all".
remainingSize
remainingSize:
bigint
SIGNED size still open afterwards. 0n on a full close.
fullClose
fullClose:
boolean
Whether closedQuantity takes the position all the way to flat.
realizedPnl
realizedPnl:
bigint
Realised price PnL on the closed share, signed.
floor((fill − entry) × sign(size) × closedQuantity / oneBase) — the port of
MarginBank._realizedPnlForClose, which FLOORS toward −∞ so a gain is credited
at most true and a loss debited at least true. A partial close leaves
avgEntryPrice untouched, so the remainder keeps its original basis.
fundingSettled
fundingSettled:
bigint
Funding settled by the close, signed and positive means the account pays.
Measured on the whole position, not the closed share — settleTrade
settles funding before it touches the position. This is the term a close modal
most often gets wrong.
fee
fee:
bigint
The fill's fee, signed — negative is a maker rebate.
netProceeds
netProceeds:
bigint
The close's total effect on collateral: realizedPnl − fundingSettled − fee.
The number to show. Funding and fee are costs, so they subtract; showing
realizedPnl alone reports a position as more profitable to close than it is.
placeable
placeable:
boolean
Whether closedQuantity clears the pool's minQuantity.
false means the close cannot be placed at all — not that it is small. A dust
position below the minimum can only leave via liquidation or ADL.
It is the pool minimum and nothing else: true is not a promise the
placement is accepted. See the note on reducing capacity in
SomniaMarketsClient.previewPerpClosePnl.
fillPrice
fillPrice:
bigint
The price the close was quoted at.
markPrice
markPrice:
bigint
Current mark.
avgEntryPrice
avgEntryPrice:
bigint
The position's entry basis, untouched by a partial close.
lotSize
lotSize:
bigint
The pool's quantity grid — the value closedQuantity was aligned to,
floored at 1n so a pool reporting 0n cannot hand back a divisor that throws.
minQuantity
minQuantity:
bigint
The pool's minimum order quantity.