createPosition call.
Lifecycle
A perp order (tradingMode: "MARGIN" with leverage) opens a position when it fills. Perps are one-way: side sets the direction, and fills on the same (marginAccountId, tradingPairId) aggregate into one net position whose size and entryPrice update as exposure is added. Omit the deprecated positionSide field.
Detect closure from
status, never from a zero size.
List Positions
FollownextPageToken until it comes back empty.
Inspect a Position
Lifetime totals status
exitPrice, realizedRoe, feesPaid, fundingPaid, cumFees and netRealizedPnl come from the position’s reducing history, which can trail the row. lifetimeTotalsStatus on every list and detail row says which case applies. Never read an absent lifetime field as zero.
LIFETIME_TOTALS_STATUS_UNSPECIFIED is never sent; treat it, and any unknown status, as unavailable. Rather than understated values: cumFees is null while fee history is unavailable; open-row fundingPaid is null whenever status is not COMPLETE; exitPrice, feesPaid and terminal fundingPaid are null when reducing executions are unavailable or don’t reconcile.
Versions and merging
version is an opaque, non-negative revision; compare only within one position, higher is newer. The WebSocket positions snapshot and ranked position_update frames carry the same value, so reconcile on positionId + version. Order by version, never updatedAt or arrival order.
0is the unranked sentinel: treat it as absent and fall back to full field comparison. A read of anOPENposition normally comes from live matching-engine state and reports0; only reads from the stored row carry a version. Never let a0read replace a ranked version.- Some live frames are unranked and omit
version. Non-zero funding frames and terminal close/liquidation/ADL frames are normally ranked. versionadvances on open, add, reduce, partial and full close, funding, margin transfer, liquidation and ADL — exactly when versioned content changed (a change undone before it is stored included). A position a command left unchanged keeps its version, so a ranked frame for an untouched sibling can carry a higher version with identical content: rank it newer.- It does not advance for the six valuation fields, re-derived on every read:
markPrice,unrealizedPnl,liquidationPrice,leverage,maintenanceMarginRequired,initialMarginRequired.leverage(opening notional over posted margin) is not mark-driven, but live surfaces derive it from engine state while stored reads serve the stored value, so the two can differ at one version. An oracle reprice advances nothing; a maintenance-margin breach or recovery restamps the positions it changed.
Terminal frames carry the lifetime reduced quantity (sum of reducing executions) and exact status: ordinary closes and flattened ADL counterparties are
CLOSED; liquidation victims, backstop exits and the bankrupt ADL side are LIQUIDATED. Their markPrice is the market’s mark when the position closed, as on the REST row, never the price of the closing fill, and is omitted when that mark is unknown; the price a position closed at is REST’s exitPrice. After a restart, a terminal frame rebuilt from older history that lacks size or margin fields omits version (incomplete size history carries only the known partial total); reconcile it by full comparison.
Timestamps
openedAt never moves. Time held is now - openedAt (open) or updatedAt - openedAt (terminal); clamp at zero, since it can sit slightly ahead of your clock and shift by server clock drift after a restart. A flip opens a new position with a new positionId and openedAt. null on REST and omitted on WebSocket when unknown; never filled with the read time. updatedAt is identical across read paths and ignores oracle reprices.
- Open positions: REST, snapshot and live frames agree to within one matching-engine step.
- Terminal REST reads carry the engine’s close instant, which can differ slightly from the live frame; older terminal rows, and any read after an engine restart, carry the storage clock and trail by storage lag.
- Engine unreachable: REST falls back to the row’s close, then last funding, then open timestamp, so a repeatedly filled position reports its opening instant until funding settles. Live frames are unaffected and fresher.
WebSocket fields
Thepositions channel carries the same identity, scope and fields as REST, including riskBucketId, marginMode, maintenanceMarginRequired, initialMarginRequired and fundingPaid (lifetime, on snapshot and every live frame). estimatedNextFundingPayment is on the snapshot and on position_valuation frames, not on live position_update frames: keep the last value you hold. REST-only: indexPrice, realizedPnl, netRealizedPnl, exitPrice, feesPaid, cumFees, lifetimeTotalsStatus. WebSocket omits fundingPaid when earlier reductions are not fully accounted for, so REST can omit it while WebSocket carries it. Mark-derived fields can differ by one oracle tick between surfaces; take them and leverage from the newest frame.
Estimated next funding payment
estimatedNextFundingPayment is what the position is expected to pay or receive at its market’s next funding settlement, in quote-asset units:
estimatedNextFundingRate is the rate getFundingState serves (see Funding Rates). The sign follows fundingPaid: positive means the position pays, negative means it receives. A LONG pays when the rate is positive, a SHORT when it is negative. To show it as a cost, negate it.
It is an estimate, taken when the row is read:
- Settlement prices at the mark at the window boundary, not the mark you read.
- The rate moves as the window collects samples, and a window with too few samples settles at zero.
- A window is not pro-rated: a position held at the boundary pays the whole window, however recently it opened.
OPEN and LIQUIDATING rows only, and absent on terminal rows and while the market has no estimate for its open window. Never read an absent value as zero. After each settlement, the amount actually charged is in the position’s funding payments (listFundingPayments, filtered by positionId) and in fundingPaid.
Parent Accounts and Risk Buckets
Positions live in risk buckets under a parent margin account (or a margin sub-account). Account fields (equity, freeCollateral, withdrawableCollateral, availableOrderCollateral, riskBucketState), listing accounts, transfers and sub-accounts are documented once in Perps Collateral.
Live Risk
PollgetPositionRisk for volatile fields instead of refetching the position.
marginRatio is the account’s maintenance requirement divided by equity, 0 with no open positions. At zero or negative equity with a requirement (bad debt) it is a maximum-distress sentinel, Decimal::MAX (~7.9e28) as a decimal string; treat any value at or above the liquidation threshold as maximal and clamp for display.
Stream with sdk.ws.positions(handler, tradingPairId?, onSnapshot?, onValuation?) and sdk.ws.liquidations(handler, tradingPairId?); omit tradingPairId for all pairs. onValuation receives periodic position_valuation frames refreshing mark-derived figures between lifecycle events; see Position Valuation Frames.
Modify Margin
Margin is adjusted through the position’s risk bucket —transferCollateralToRiskBucket to add, transferCollateralFromMarginAccount to release — moving collateral to and from the parent margin account. Adding lowers liquidation risk and effective leverage without changing size; fund the parent first if it has no free collateral. See Transfers.
Close Positions
closePosition submits a closing order; the position is not CLOSED until it fills. The response carries the close-order ID — confirm via order events or by polling.
LIMIT and IOC (sent as LIMIT+IOC) require limitPrice; only MARKET omits it. A delegated-agent close is checked like order creation: the active delegation must allow the market, action and any perps-account scope.
A full close (no quantity) names its position. If that position closed before the matching engine reaches the order (you closed from a stale read), the close returns status: "FAILED" with close_position names a position that is no longer open, ahead of any liquidity check. A position the engine no longer holds and whose stored status is not OPEN is refused up front with 400 (Only open positions can be closed).
Batch Close All
batchCloseAllPositions submits a MARKET reduce-only close for every open perp position the caller owns.
tradingPairId(one pair) ortradingPairIds(up to 256), not both. Repeated ids are ignored; a pair with no position closes nothing.side(LONG/SHORT) narrows either filter.- No pair filter closes everything. An empty
tradingPairIdsequals no filter on the wire, so the SDK rejects[]withValidationError— never turn a filter that matched nothing into a close-all. - The body is strict: an unknown field (e.g.
tradingPairIDs) returns400and closes nothing. - Delegated sessions must pass
tradingPairIdor non-emptytradingPairIds;sidealone doesn’t count.
results. totalClosed counts closes the matching engine accepted (SUCCESS, PARTIAL, PENDING), which are not CLOSED until they fill.
Position History
UI Rules
- Sort by risk or unrealized PnL, not just creation time.
- Show liquidation distance and margin ratio by every open position; label cross values conditional.
- Default close modals to full-size market close, with optional partial size and limit price.
- Order tickets: opening or adding to a long is
BUY; reducing it isSELL+reduceOnly: true. - Show stale state when a
getPositionRiskpoll fails.
Errors To Handle
See also: Order Management for risk-bucket routing, reduce-only and TP/SL orders; Margin; TypeScript positions.

