@somnia-chain/markets-sdk


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

Type Alias: IndexedPerpPosition

IndexedPerpPosition = object

Defined in: packages/sdk/src/perp/state.ts:288

One account's position in one perp pool as the INDEXER has it — the mirror of the PerpPosition entity, and the batch counterpart to the per-pool chain read client.getPerpPosition.

This is a snapshot, not the live position. The row is upserted on each MarginBank.PositionUpdated, so it is current as of updatedAtBlock and no fresher. Everything mark-dependent — unrealized PnL, liquidation price, margin health — needs a chain read on top; nothing here is marked to market.

Numeric fields are decimal STRINGS of raw units (the indexer wire format), unlike PerpPosition, whose chain reads are bigint.

Properties

id

id: string

Defined in: packages/sdk/src/perp/state.ts:290

Row id (${pool}_${account}).


pool

pool: string

Defined in: packages/sdk/src/perp/state.ts:292

Perp pool the position is in (lowercased).


account

account: string

Defined in: packages/sdk/src/perp/state.ts:294

Position owner (lowercased).


size

size: string

Defined in: packages/sdk/src/perp/state.ts:303

SIGNED position size in raw base units: positive = long, negative = short.

Normalized to match PerpPosition.size. The entity itself stores an absolute size plus a separate isLong flag; carrying that second field here would mean two exported position types whose size means different things, which reads correctly for longs and silently inverts every short.


avgEntryPrice

avgEntryPrice: string | null

Defined in: packages/sdk/src/perp/state.ts:312

Volume-weighted average entry price, raw quote units per whole base.

The same quantity as PerpPosition.avgEntryPrice, written straight from the event. (The underlying entity column is named entryPriceX18, which is a misnomer — the value is NOT 1e18-scaled. Renamed at this boundary so the name cannot imply a rescale that never happened.)


lastUpdateRealizedPnl

lastUpdateRealizedPnl: string | null

Defined in: packages/sdk/src/perp/state.ts:322

Realized PnL from the MOST RECENT position update only (signed; zero for opens and increases).

Not cumulative, and never summable. There is one row per position, not one per update, and each update OVERWRITES this field — so prior values are gone and neither summing across positions nor accumulating over time yields lifetime realized PnL. It is a property of the last update, nothing more.


updatedAt

updatedAt: string

Defined in: packages/sdk/src/perp/state.ts:327

Unix SECONDS of the last update. (PerpPosition is NANOseconds — the two are 1e9 apart, so never compare them without converting.)


updatedAtBlock

updatedAtBlock: number | null

Defined in: packages/sdk/src/perp/state.ts:329

Block of the last update — the row is current as of this height, not head.