@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:271

Average cost per whole token of this outcome (raw collateral per token), for DISPLAY. 0n when the leg holds nothing. A rate, not an amount: does not sum across legs.

It is rounded independently of BinaryOutcomePositionPnL.costBasis, and the two do NOT reconstruct each other. costBasis comes straight off the aggregate book (balance * cost / quantity); this rate floors that same book to one whole token, and each floor loses a different remainder. They can even disagree in kind: on a zero-decimal collateral a leg of 5 tokens costing 2 has a costBasis of 2 and an avgCost of 0, because a per-token rate under one raw unit has nowhere to go.

So value a position with costBasis, and show avgCost. Deriving either from the other returns a different number in ~2999 of 3000 awkward-quantity cases, which is why both are published.


markPrice

markPrice: bigint | null

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

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

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

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


realizedPnl

realizedPnl: bigint

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

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