Order types define the structure and parameters for placing and managing orders.
Order
Represents an active order on the Drift Protocol.
Current order status (INIT, OPEN, FILLED, CANCELED)
Type of order (LIMIT, MARKET, TRIGGER_MARKET, TRIGGER_LIMIT, ORACLE)
Market type (PERP or SPOT)
Solana slot when order was placed
Unique order identifier assigned by the protocol
User-defined order identifier
Index of the market for this order
Limit price in PRICE_PRECISION (1e6)
Amount of base asset to trade
Amount of quote asset for the order
Amount of base asset already filled
Amount of quote asset already filled
direction
PositionDirection
required
Order direction (LONG or SHORT)
Whether this order can only reduce position size
Price at which trigger order activates
triggerCondition
OrderTriggerCondition
required
Condition for trigger activation (ABOVE, BELOW, etc.)
Whether order must be maker-only
Whether order should be cancelled if not immediately filled
Offset from oracle price for oracle orders
Duration of order auction in slots
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.
Market type (PERP or SPOT)
direction
PositionDirection
required
Order direction (LONG or SHORT)
Amount of base asset to trade
Limit price in PRICE_PRECISION
Whether order can only reduce position
Post-only behavior (NONE, MUST_POST_ONLY, TRY_POST_ONLY, SLIDE)
User-defined order identifier
Trigger price for trigger orders
triggerCondition
OrderTriggerCondition
required
Trigger condition (ABOVE or BELOW)
Offset from oracle price for oracle orders
Auction duration in slots
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).
Market type (PERP or SPOT)
direction
PositionDirection
required
Order direction for all orders
Total base asset amount to distribute across all orders
Starting price for the scale (in PRICE_PRECISION)
Ending price for the scale (in PRICE_PRECISION)
Number of orders to place (min 2, max 32)
How to distribute sizes (FLAT, ASCENDING, DESCENDING)
Whether orders should be reduce-only
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.
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.
Timestamp of the order event
export type OrderRecord = {
ts: BN;
user: PublicKey;
order: Order;
};
OrderActionRecord
Event record for order actions (fills, cancellations, etc.).
Type of action (PLACE, CANCEL, EXPIRE, FILL, TRIGGER)
actionExplanation
OrderActionExplanation
required
Detailed explanation of the action
Account that filled the order (for fills)
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,
};