@somnia-chain/markets-sdk


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

Interface: BinaryOutcomePositionPnL

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

One outcome's half of a binary position, RAW units — the YES or NO book on its own, as the fold already computes it before summing into the market totals.

Why this exists. Every money field on BinaryPositionPnL is blended across both outcomes, which is unusable for a wallet holding BOTH. Buy 10 YES at 0.20 and 10 NO at 0.80, mark YES at 0.40: the legs are +2.00 and -2.00 and the blended unrealizedPnl is 0.00. Neither position row can show that zero as its own PnL.

Legs are only reachable through a position row, so the key that names one (yes / no) is also the only label it needs.

Legs sum EXACTLY to the totals — costBasis, markValue, unrealizedPnl and realizedPnl are stored here first and added up, so integer division cannot make a leg disagree with the total it belongs to. avgCost and markPrice are per-token rates and do NOT sum.

Properties

balance

balance: bigint

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

This outcome's current token balance (raw).


costBasis

costBasis: bigint

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

Remaining cost basis of THIS leg's balance (raw collateral).


avgCost

avgCost: bigint

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

Fills-derived average cost per whole token of this outcome (raw collateral per token) — the rate used to value balance. 0n when the leg holds nothing. A rate, not an amount: does not sum across legs.

NOT derivable from the other two. costBasis is balance * avgCost / oneCollateral, and that division is lossy: recomputing costBasis * oneCollateral / balance returns a different number in ~2999 of 3000 awkward-quantity cases. It is published because a consumer cannot get it back.


markPrice

markPrice: bigint

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

The price this leg is marked at (raw collateral per whole token): the book-clamped last price while trading, or the settlement payout once resolved. A rate: does not sum, but while trading the two legs' prices add up to one whole collateral unit.


markValue

markValue: bigint

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

Mark value of this leg's balance (raw collateral).


unrealizedPnl

unrealizedPnl: bigint

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

This leg's markValue - costBasis (raw, signed).


realizedPnl

realizedPnl: bigint

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

Realized PnL from this outcome's sells (raw, signed).