@somnia-chain/markets-sdk


@somnia-chain/markets-sdk / index / computePositionPnL

Function: computePositionPnL()

computePositionPnL(events, balances, market, oneCollateral, opts?): BinaryPositionPnL

Defined in: packages/sdk/src/derivedReads.ts:407

Fold a PnLEvent stream (oldest-first) + current balances into a BinaryPositionPnL, avg-cost basis, RAW units. oneCollateral = 10^quoteDecimals. Prices arrive in YES terms; a NO event is re-expressed to NO terms (oneCollateral − yesPrice) here so the two books stay separate.

Parameters

events

PnLEvent[]

balances

balanceYes

bigint

balanceNo

bigint

market

Pick<BinaryMarket, "quoteDecimals" | "lastPrice" | "winningOutcome" | "voided">

oneCollateral

bigint

opts?

bookTop?

YesBookTop

Top of the YES book — clamps the mark to live quotes (see markYesPrice).

Returns

BinaryPositionPnL