Overview
OrderParams defines the complete configuration for placing orders on Drift Protocol. The SDK provides helper functions to create specific order types with sensible defaults.OrderParams Type
The type of order to place.OrderType variants:
OrderType.LIMIT- Limit order with specified priceOrderType.MARKET- Market order executed at best available priceOrderType.TRIGGER_MARKET- Triggers a market order when condition is metOrderType.TRIGGER_LIMIT- Triggers a limit order when condition is metOrderType.ORACLE- Order priced relative to oracle price
Market type for the order.MarketType variants:
MarketType.PERP- Perpetual futures marketMarketType.SPOT- Spot market
Direction of the order.PositionDirection variants:
PositionDirection.LONG- Buy/long positionPositionDirection.SHORT- Sell/short position
Amount of base asset to trade, in base precision (typically 1e9 for most markets).
Limit price for the order in PRICE_PRECISION (1e6). Set to 0 for market orders.
Index of the market to trade on.
User-defined order ID for tracking. Must be unique per user.
If true, order can only reduce existing position, not increase or flip it.
Post-only constraint for the order.PostOnlyParams variants:
PostOnlyParams.NONE- No post-only constraintPostOnlyParams.MUST_POST_ONLY- Transaction fails if order can’t be post-onlyPostOnlyParams.TRY_POST_ONLY- Order not placed if it can’t be post-onlyPostOnlyParams.SLIDE- Price adjusted to be post-only if needed
Bit flags for order options.OrderParamsBitFlag values:
OrderParamsBitFlag.ImmediateOrCancel(1) - Cancel unfilled portion immediatelyOrderParamsBitFlag.UpdateHighLeverageMode(2) - Update high leverage mode
Trigger price for trigger orders in PRICE_PRECISION (1e6). Required for TRIGGER_MARKET and TRIGGER_LIMIT orders.
Condition for trigger activation.OrderTriggerCondition variants:
OrderTriggerCondition.ABOVE- Trigger when price goes above trigger priceOrderTriggerCondition.BELOW- Trigger when price goes below trigger priceOrderTriggerCondition.TRIGGERED_ABOVE- Trigger condition above has been metOrderTriggerCondition.TRIGGERED_BELOW- Trigger condition below has been met
Price offset from oracle price in basis points. Used for floating limit orders.
Duration of the auction phase in slots. During auction, order transitions from taking to resting.
Maximum timestamp (Unix seconds) for order validity. Order expires after this time.
Starting price for auction in PRICE_PRECISION (1e6).
Ending price for auction in PRICE_PRECISION (1e6).
Helper Functions
getOrderParams
Creates an OrderParams object with default values merged with provided parameters.optionalOrderParams(OptionalOrderParams) - Order parameters to setoverridingParams(Record<string, any>) - Additional parameters to override
getLimitOrderParams
Creates parameters for a limit order.params- Order parameters excluding orderTypeparams.price(BN) - Required limit price
getMarketOrderParams
Creates parameters for a market order.params- Order parameters excluding orderType
getTriggerMarketOrderParams
Creates parameters for a trigger market order (stop loss or take profit).params- Order parameters excluding orderTypeparams.triggerCondition(OrderTriggerCondition) - Required trigger conditionparams.triggerPrice(BN) - Required trigger price
getTriggerLimitOrderParams
Creates parameters for a trigger limit order.params- Order parameters excluding orderTypeparams.triggerCondition(OrderTriggerCondition) - Required trigger conditionparams.triggerPrice(BN) - Required trigger priceparams.price(BN) - Required limit price after trigger
Scale Orders
Scale orders allow placing multiple limit orders distributed across a price range.ScaleOrderParams
Market type for the orders.
Direction of the orders.
Index of the market.
Total base asset amount to distribute across all orders.
Starting price for the scale in PRICE_PRECISION (1e6).
Ending price for the scale in PRICE_PRECISION (1e6).
Number of orders to place (min 2, max 32). Total open orders cannot exceed 32.
How to distribute sizes across orders.SizeDistribution variants:
SizeDistribution.FLAT- Equal size for all ordersSizeDistribution.ASCENDING- Smallest at start price, largest at end priceSizeDistribution.DESCENDING- Largest at start price, smallest at end price
Whether orders should be reduce-only.
Post-only setting for all orders.
Bit flags for the orders.
Maximum timestamp for orders to be valid.
Utility Functions
isUpdateHighLeverageMode
Checks if the UpdateHighLeverageMode bit flag is set.bitFlags(number) - Bit flags to check
Default Values
The SDK provides default values for all optional order parameters:Related Types
OptionalOrderParams
All fields from OrderParams are optional except:orderTypemarketIndexbaseAssetAmountdirection
ModifyOrderParams
Used for modifying existing orders. All OrderParams fields are optional and nullable, plus:Policy for order modification.ModifyOrderPolicy enum:
ModifyOrderPolicy.MustModify(1) - Transaction fails if order cannot be modifiedModifyOrderPolicy.ExcludePreviousFill(2) - Exclude previously filled amount
See Also
- Position Management - Calculate position metrics and PnL
- DLOB - Decentralized Limit Order Book for order matching