Skip to main content
Order types define the structure and parameters for placing and managing orders.

Order

Represents an active order on the Drift Protocol.
status
OrderStatus
required
Current order status (INIT, OPEN, FILLED, CANCELED)
orderType
OrderType
required
Type of order (LIMIT, MARKET, TRIGGER_MARKET, TRIGGER_LIMIT, ORACLE)
marketType
MarketType
required
Market type (PERP or SPOT)
slot
BN
required
Solana slot when order was placed
orderId
number
required
Unique order identifier assigned by the protocol
userOrderId
number
required
User-defined order identifier
marketIndex
number
required
Index of the market for this order
price
BN
required
Limit price in PRICE_PRECISION (1e6)
baseAssetAmount
BN
required
Amount of base asset to trade
quoteAssetAmount
BN
required
Amount of quote asset for the order
baseAssetAmountFilled
BN
required
Amount of base asset already filled
quoteAssetAmountFilled
BN
required
Amount of quote asset already filled
direction
PositionDirection
required
Order direction (LONG or SHORT)
reduceOnly
boolean
required
Whether this order can only reduce position size
triggerPrice
BN
required
Price at which trigger order activates
triggerCondition
OrderTriggerCondition
required
Condition for trigger activation (ABOVE, BELOW, etc.)
postOnly
boolean
required
Whether order must be maker-only
immediateOrCancel
boolean
required
Whether order should be cancelled if not immediately filled
oraclePriceOffset
number
required
Offset from oracle price for oracle orders
auctionDuration
number
required
Duration of order auction in slots
maxTs
BN
required
Maximum timestamp for order validity
export type Order = {
  status: OrderStatus;
  orderType: OrderType;
  marketType: MarketType;
  slot: BN;
  orderId: number;
  userOrderId: number;
  marketIndex: number;
  price: BN;
  baseAssetAmount: BN;
  quoteAssetAmount: BN;
  baseAssetAmountFilled: BN;
  quoteAssetAmountFilled: BN;
  direction: PositionDirection;
  reduceOnly: boolean;
  triggerPrice: BN;
  triggerCondition: OrderTriggerCondition;
  existingPositionDirection: PositionDirection;
  postOnly: boolean;
  immediateOrCancel: boolean;
  oraclePriceOffset: number;
  auctionDuration: number;
  auctionStartPrice: BN;
  auctionEndPrice: BN;
  maxTs: BN;
  bitFlags: number;
  postedSlotTail: number;
};

OrderParams

Parameters for placing a new order.
orderType
OrderType
required
Type of order to place
marketType
MarketType
required
Market type (PERP or SPOT)
direction
PositionDirection
required
Order direction (LONG or SHORT)
baseAssetAmount
BN
required
Amount of base asset to trade
price
BN
required
Limit price in PRICE_PRECISION
marketIndex
number
required
Index of the market
reduceOnly
boolean
required
Whether order can only reduce position
postOnly
PostOnlyParams
required
Post-only behavior (NONE, MUST_POST_ONLY, TRY_POST_ONLY, SLIDE)
userOrderId
number
required
User-defined order identifier
triggerPrice
BN | null
Trigger price for trigger orders
triggerCondition
OrderTriggerCondition
required
Trigger condition (ABOVE or BELOW)
oraclePriceOffset
number | null
Offset from oracle price for oracle orders
auctionDuration
number | null
Auction duration in slots
maxTs
BN | null
Maximum timestamp for order validity
export type OrderParams = {
  orderType: OrderType;
  marketType: MarketType;
  userOrderId: number;
  direction: PositionDirection;
  baseAssetAmount: BN;
  price: BN;
  marketIndex: number;
  reduceOnly: boolean;
  postOnly: PostOnlyParams;
  bitFlags: number;
  triggerPrice: BN | null;
  triggerCondition: OrderTriggerCondition;
  oraclePriceOffset: number | null;
  auctionDuration: number | null;
  maxTs: BN | null;
  auctionStartPrice: BN | null;
  auctionEndPrice: BN | null;
};

ScaleOrderParams

Parameters for placing scale orders (multiple orders across a price range).
marketType
MarketType
required
Market type (PERP or SPOT)
direction
PositionDirection
required
Order direction for all orders
marketIndex
number
required
Market index
totalBaseAssetAmount
BN
required
Total base asset amount to distribute across all orders
startPrice
BN
required
Starting price for the scale (in PRICE_PRECISION)
endPrice
BN
required
Ending price for the scale (in PRICE_PRECISION)
orderCount
number
required
Number of orders to place (min 2, max 32)
sizeDistribution
SizeDistribution
required
How to distribute sizes (FLAT, ASCENDING, DESCENDING)
reduceOnly
boolean
required
Whether orders should be reduce-only
postOnly
PostOnlyParams
required
Post-only setting for all orders
export type ScaleOrderParams = {
  marketType: MarketType;
  direction: PositionDirection;
  marketIndex: number;
  totalBaseAssetAmount: BN;
  startPrice: BN;
  endPrice: BN;
  orderCount: number;
  sizeDistribution: SizeDistribution;
  reduceOnly: boolean;
  postOnly: PostOnlyParams;
  bitFlags: number;
  maxTs: BN | null;
};

ModifyOrderParams

Parameters for modifying an existing order.
policy
ModifyOrderPolicy
Modification policy (MUST_MODIFY, EXCLUDE_PREVIOUS_FILL)
All fields from OrderParams can be provided as optional overrides.
export type ModifyOrderParams = {
  [Property in keyof OrderParams]?: OrderParams[Property] | null;
} & { policy?: ModifyOrderPolicy };

export enum ModifyOrderPolicy {
  MustModify = 1,
  ExcludePreviousFill = 2,
}

OrderRecord

Event record for order placements.
ts
BN
required
Timestamp of the order event
user
PublicKey
required
User account public key
order
Order
required
The order details
export type OrderRecord = {
  ts: BN;
  user: PublicKey;
  order: Order;
};

OrderActionRecord

Event record for order actions (fills, cancellations, etc.).
ts
BN
required
Timestamp of the action
action
OrderAction
required
Type of action (PLACE, CANCEL, EXPIRE, FILL, TRIGGER)
actionExplanation
OrderActionExplanation
required
Detailed explanation of the action
marketIndex
number
required
Market index
marketType
MarketType
required
Market type
filler
PublicKey | null
Account that filled the order (for fills)
baseAssetAmountFilled
BN | null
Amount filled
takerFee
BN | null
Taker fee paid
makerFee
BN | null
Maker fee paid/rebate received
export type OrderActionRecord = {
  ts: BN;
  action: OrderAction;
  actionExplanation: OrderActionExplanation;
  marketIndex: number;
  marketType: MarketType;
  filler: PublicKey | null;
  fillerReward: BN | null;
  fillRecordId: BN | null;
  baseAssetAmountFilled: BN | null;
  quoteAssetAmountFilled: BN | null;
  takerFee: BN | null;
  makerFee: BN | null;
  referrerReward: number | null;
  quoteAssetAmountSurplus: BN | null;
  taker: PublicKey | null;
  takerOrderId: number | null;
  takerOrderDirection: PositionDirection | null;
  maker: PublicKey | null;
  makerOrderId: number | null;
  makerOrderDirection: PositionDirection | null;
  oraclePrice: BN;
  // ... additional fields
};

Default Order Parameters

Default values for order parameters:
export const DefaultOrderParams: OrderParams = {
  orderType: OrderType.MARKET,
  marketType: MarketType.PERP,
  userOrderId: 0,
  direction: PositionDirection.LONG,
  baseAssetAmount: ZERO,
  price: ZERO,
  marketIndex: 0,
  reduceOnly: false,
  postOnly: PostOnlyParams.NONE,
  bitFlags: 0,
  triggerPrice: null,
  triggerCondition: OrderTriggerCondition.ABOVE,
  oraclePriceOffset: null,
  auctionDuration: null,
  maxTs: null,
  auctionStartPrice: null,
  auctionEndPrice: null,
};

Build docs developers (and LLMs) love