@somnia-chain/markets-sdk


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

Function: computeBinaryPnl()

computeBinaryPnl(fills, balances, market, opts?): BinaryPnl

Defined in: packages/sdk/src/units.ts:269

Realized + unrealized binary PnL for one account, avg-cost basis — a PURE helper (no indexer/chain dependency). fills are the account's own trades (from binaryFillsFor); balances its current YES/NO holdings (from getOutcomeBalances); market supplies decimals + resolution state.

Realized PnL accrues on sells (proceeds − avg cost of the tokens sold). Unrealized marks the remaining position: to the book-clamped last price while trading (see markYesPrice; pass opts.bookTop so a live quote beyond a stale print corrects the mark), and to the settlement payout (1 for the winning outcome, 0 for the loser, 0.5 each when voided) once resolved.

Parameters

fills

BinaryPnlFill[]

balances

OutcomeBalances

market

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

opts?

bookTop?

YesBookTop

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

Returns

BinaryPnl