Skip to main content

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

OrderType
required
The type of order to place.OrderType variants:
  • OrderType.LIMIT - Limit order with specified price
  • OrderType.MARKET - Market order executed at best available price
  • OrderType.TRIGGER_MARKET - Triggers a market order when condition is met
  • OrderType.TRIGGER_LIMIT - Triggers a limit order when condition is met
  • OrderType.ORACLE - Order priced relative to oracle price
MarketType
required
Market type for the order.MarketType variants:
  • MarketType.PERP - Perpetual futures market
  • MarketType.SPOT - Spot market
PositionDirection
required
Direction of the order.PositionDirection variants:
  • PositionDirection.LONG - Buy/long position
  • PositionDirection.SHORT - Sell/short position
BN
required
Amount of base asset to trade, in base precision (typically 1e9 for most markets).
BN
required
Limit price for the order in PRICE_PRECISION (1e6). Set to 0 for market orders.
number
required
Index of the market to trade on.
number
default:"0"
User-defined order ID for tracking. Must be unique per user.
boolean
default:"false"
If true, order can only reduce existing position, not increase or flip it.
PostOnlyParams
default:"PostOnlyParams.NONE"
Post-only constraint for the order.PostOnlyParams variants:
  • PostOnlyParams.NONE - No post-only constraint
  • PostOnlyParams.MUST_POST_ONLY - Transaction fails if order can’t be post-only
  • PostOnlyParams.TRY_POST_ONLY - Order not placed if it can’t be post-only
  • PostOnlyParams.SLIDE - Price adjusted to be post-only if needed
number
default:"0"
Bit flags for order options.OrderParamsBitFlag values:
  • OrderParamsBitFlag.ImmediateOrCancel (1) - Cancel unfilled portion immediately
  • OrderParamsBitFlag.UpdateHighLeverageMode (2) - Update high leverage mode
BN | null
default:"null"
Trigger price for trigger orders in PRICE_PRECISION (1e6). Required for TRIGGER_MARKET and TRIGGER_LIMIT orders.
OrderTriggerCondition
default:"OrderTriggerCondition.ABOVE"
Condition for trigger activation.OrderTriggerCondition variants:
  • OrderTriggerCondition.ABOVE - Trigger when price goes above trigger price
  • OrderTriggerCondition.BELOW - Trigger when price goes below trigger price
  • OrderTriggerCondition.TRIGGERED_ABOVE - Trigger condition above has been met
  • OrderTriggerCondition.TRIGGERED_BELOW - Trigger condition below has been met
number | null
default:"null"
Price offset from oracle price in basis points. Used for floating limit orders.
number | null
default:"null"
Duration of the auction phase in slots. During auction, order transitions from taking to resting.
BN | null
default:"null"
Maximum timestamp (Unix seconds) for order validity. Order expires after this time.
BN | null
default:"null"
Starting price for auction in PRICE_PRECISION (1e6).
BN | null
default:"null"
Ending price for auction in PRICE_PRECISION (1e6).

Helper Functions

getOrderParams

Creates an OrderParams object with default values merged with provided parameters.
Parameters:
  • optionalOrderParams (OptionalOrderParams) - Order parameters to set
  • overridingParams (Record<string, any>) - Additional parameters to override
Returns: Complete OrderParams object

getLimitOrderParams

Creates parameters for a limit order.
Parameters:
  • params - Order parameters excluding orderType
  • params.price (BN) - Required limit price
Returns: OptionalOrderParams with orderType set to LIMIT

getMarketOrderParams

Creates parameters for a market order.
Parameters:
  • params - Order parameters excluding orderType
Returns: OptionalOrderParams with orderType set to MARKET

getTriggerMarketOrderParams

Creates parameters for a trigger market order (stop loss or take profit).
Parameters:
  • params - Order parameters excluding orderType
  • params.triggerCondition (OrderTriggerCondition) - Required trigger condition
  • params.triggerPrice (BN) - Required trigger price
Returns: OptionalOrderParams with orderType set to TRIGGER_MARKET

getTriggerLimitOrderParams

Creates parameters for a trigger limit order.
Parameters:
  • params - Order parameters excluding orderType
  • params.triggerCondition (OrderTriggerCondition) - Required trigger condition
  • params.triggerPrice (BN) - Required trigger price
  • params.price (BN) - Required limit price after trigger
Returns: OptionalOrderParams with orderType set to TRIGGER_LIMIT

Scale Orders

Scale orders allow placing multiple limit orders distributed across a price range.

ScaleOrderParams

MarketType
required
Market type for the orders.
PositionDirection
required
Direction of the orders.
number
required
Index of the market.
BN
required
Total base asset amount to distribute across all orders.
BN
required
Starting price for the scale in PRICE_PRECISION (1e6).
BN
required
Ending price for the scale in PRICE_PRECISION (1e6).
number
required
Number of orders to place (min 2, max 32). Total open orders cannot exceed 32.
SizeDistribution
required
How to distribute sizes across orders.SizeDistribution variants:
  • SizeDistribution.FLAT - Equal size for all orders
  • SizeDistribution.ASCENDING - Smallest at start price, largest at end price
  • SizeDistribution.DESCENDING - Largest at start price, smallest at end price
boolean
required
Whether orders should be reduce-only.
PostOnlyParams
required
Post-only setting for all orders.
number
required
Bit flags for the orders.
BN | null
required
Maximum timestamp for orders to be valid.

Utility Functions

isUpdateHighLeverageMode

Checks if the UpdateHighLeverageMode bit flag is set.
Parameters:
  • bitFlags (number) - Bit flags to check
Returns: boolean - True if UpdateHighLeverageMode flag is set

Default Values

The SDK provides default values for all optional order parameters:

OptionalOrderParams

All fields from OrderParams are optional except:
  • orderType
  • marketIndex
  • baseAssetAmount
  • direction

ModifyOrderParams

Used for modifying existing orders. All OrderParams fields are optional and nullable, plus:
ModifyOrderPolicy
Policy for order modification.ModifyOrderPolicy enum:
  • ModifyOrderPolicy.MustModify (1) - Transaction fails if order cannot be modified
  • ModifyOrderPolicy.ExcludePreviousFill (2) - Exclude previously filled amount

See Also

  • Position Management - Calculate position metrics and PnL
  • DLOB - Decentralized Limit Order Book for order matching