Position Types
Drift Protocol manages two types of positions: perpetual futures positions and spot positions.Perpetual Positions
Perpetual positions represent a user’s exposure to a perpetual market.Position Structure
sdk/src/types.ts
Position Direction
sdk/src/types.ts
Position Flags
Positions can have special flags that affect their behavior:sdk/src/types.ts
Isolated positions use dedicated collateral and don’t share risk with other positions. They were introduced in v2.154.0.
Spot Positions
Spot positions represent deposits or borrows in a spot market.Spot Position Structure
sdk/src/types.ts
Token Amount Calculation
The actual token amount is calculated from the scaled balance:cumulativeInterest is either cumulativeDepositInterest or cumulativeBorrowInterest from the spot market, depending on the balance type.
PnL Calculations
Unrealized PnL
Unrealized PnL is calculated as the difference between current position value and entry cost:sdk/src/math/position.ts
baseAssetValue= current market value of the positionsign(baseAssetAmount)= 1 for long, -1 for shortquoteAssetAmount= negative of the quote used to open position
Including Funding Payments
WhenwithFunding = true, unsettled funding payments are included:
Base Asset Value
The base asset value calculation uses the AMM to determine the exit price:sdk/src/math/position.ts
Break-Even Price
The break-even price includes entry price plus fees and funding: ThequoteBreakEvenAmount is updated when:
- Opening/closing positions (includes trading fees)
- Settling funding payments
- Taking maker rebates
Position Management
Opening Positions
Positions are opened or increased through order fills. When a long order fills:baseAssetAmountincreasesquoteAssetAmountdecreases by the fill quote amountquoteEntryAmountis updated for cost basis trackingquoteBreakEvenAmountincludes fees- Funding rate checkpoint is updated
Closing Positions
When closing a position:baseAssetAmountdecreases toward zeroquoteAssetAmountincreases by the exit quote amount- PnL is realized and moved to
settledPnl - If fully closed, position is reset
Flipping Positions
When an order flips a position (e.g., long → short):- Old position is fully closed and PnL realized
- New position is opened in opposite direction
- Entry amounts are reset for the new position
Margin Calculations
Position Value for Margin
For margin calculations, positions are valued differently than for PnL:sdk/src/math/margin.ts
Worst-Case Base Amount
WhenincludeOpenOrders = true, margin calculations use worst-case scenarios:
sdk/src/math/margin.ts
- Current position
- All open bids (could increase long or decrease short)
- All open asks (could increase short or decrease long)
Liability Value
For prediction markets, liability is calculated differently:Isolated Positions
Introduced in v2.154.0, isolated positions use dedicated collateral.Creating Isolated Positions
When opening an isolated position:- Deposit collateral into
isolatedPositionScaledBalance - Position is flagged with
PositionFlag.IsolatedPosition - Only the isolated collateral backs this position
- Position cannot use cross-margin collateral
Isolated Position Constraints
- Only one isolated position allowed per market
- Must be in an
ISOLATEDtier market - Cannot mix with cross-margin positions in same market
- Liquidation affects only the isolated position
LP Positions
Users can provide liquidity to the AMM:LP Shares
When adding liquidity:- User receives
lpSharesproportional to deposit - User’s position in the market is effectively transferred to the AMM
- LP earns a portion of trading fees
- LP shares PnL of the AMM position
Removing Liquidity
When removing liquidity:- LP shares are burned
- User receives their proportional share of:
- Base asset position from AMM
- Quote asset from AMM
- Accrued fees
LP positions are subject to a cooldown period (typically 24 hours) after adding liquidity before removal is allowed.
Position Limits
Max Positions
Each user account can have:- Up to 8 perp positions
- Up to 8 spot positions
- Up to 32 open orders
Open Interest Limits
Markets may have maximum open interest caps:Next Steps
Orders
Learn how orders create and modify positions
Margin System
Understand margin requirements for positions
Liquidations
See how underwater positions are liquidated
Markets
Review market mechanics and parameters