@somnia-chain/markets-sdk


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

Interface: BinaryOutcomePositionPnL

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

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:251

This outcome's current token balance (raw).


costBasis

costBasis: bigint

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

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


avgCost

avgCost: bigint

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

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 | null

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

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.

null when the market has NO price to mark against — it has never traded and no book top was supplied, so markYesPrice returns null. Do not read that as 0n: a zero YES mark is also a FULL-collateral NO mark, which reports a fabricated total loss on one leg and a fabricated total gain on the other. markValue and unrealizedPnl are null with it, because both are derived from this price.


markValue

markValue: bigint | null

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

Mark value of this leg's balance (raw collateral); null when markPrice is unknown.


unrealizedPnl

unrealizedPnl: bigint | null

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

This leg's markValue - costBasis (raw, signed); null when markPrice is unknown.


realizedPnl

realizedPnl: bigint

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

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