Skip to main content

Order

Represents an order in the Drift protocol. Contains all information about an order including its status, type, price, and fill information.

Fields

slot
u64
Slot when the order was placed
price
u64
The limit price for the order (in quote asset units)
base_asset_amount
u64
The amount of base asset to buy or sell
base_asset_amount_filled
u64
The amount of base asset filled so far
quote_asset_amount_filled
u64
The amount of quote asset filled so far
trigger_price
u64
Price at which a trigger order will be executed
auction_start_price
i64
Starting price for auction orders
auction_end_price
i64
Ending price for auction orders
max_ts
i64
Maximum timestamp for order validity
oracle_price_offset
i32
Offset from oracle price for oracle-based orders
order_id
u32
Unique order ID assigned by the protocol
market_index
u16
Index of the market this order is for
status
OrderStatus
Current status of the order (e.g., Open, Filled, Cancelled)
order_type
OrderType
Type of order (e.g., Market, Limit, TriggerMarket, TriggerLimit)
market_type
MarketType
Whether this is a Spot or Perp order
user_order_id
u8
User-defined order ID for easier tracking
existing_position_direction
PositionDirection
Direction of the existing position (Long or Short)
direction
PositionDirection
Direction of this order (Long or Short)
reduce_only
bool
If true, order can only reduce an existing position
post_only
bool
If true, order will only be placed as a maker order
immediate_or_cancel
bool
If true, order will be cancelled if not immediately filled
trigger_condition
OrderTriggerCondition
Condition for trigger orders (Above, Below, etc.)
auction_duration
u8
Duration of the auction period in slots
posted_slot_tail
u8
Lower 8 bits of the slot when order was posted
bit_flags
u8
Bit flags for additional order properties

OrderParams

Parameters used to place a new order. This struct is passed to order placement functions.

Fields

order_type
OrderType
required
Type of order (Market, Limit, TriggerMarket, TriggerLimit, Oracle)
market_type
MarketType
required
Spot or Perp market
direction
PositionDirection
required
Long or Short
user_order_id
u8
required
User-defined ID for tracking (0-255)
base_asset_amount
u64
required
Amount of base asset to trade
price
u64
required
Limit price for the order
market_index
u16
required
Index of the market to trade on
reduce_only
bool
required
Whether this order can only reduce existing position
post_only
PostOnlyParam
required
Post-only behavior (None, MustPostOnly, TryPostOnly, Slide)
bit_flags
u8
required
Additional order flags
max_ts
Option<i64>
Maximum timestamp for order validity
trigger_price
Option<u64>
Trigger price for conditional orders
trigger_condition
OrderTriggerCondition
required
Trigger condition (Above, Below, TriggeredAbove, TriggeredBelow)
oracle_price_offset
Option<i32>
Offset from oracle price (for oracle orders)
auction_duration
Option<u8>
Duration of auction period in slots
auction_start_price
Option<i64>
Starting price for auction
auction_end_price
Option<i64>
Ending price for auction

Example

use drift_rs::types::{OrderParams, OrderType, MarketType, PositionDirection, PostOnlyParam, OrderTriggerCondition};

// Create a limit order
let order_params = OrderParams {
    order_type: OrderType::Limit,
    market_type: MarketType::Perp,
    direction: PositionDirection::Long,
    user_order_id: 1,
    base_asset_amount: 1_000_000_000, // 1 SOL (9 decimals)
    price: 100_000_000, // $100 (6 decimals)
    market_index: 0,
    reduce_only: false,
    post_only: PostOnlyParam::None,
    bit_flags: 0,
    max_ts: None,
    trigger_price: None,
    trigger_condition: OrderTriggerCondition::Above,
    oracle_price_offset: None,
    auction_duration: None,
    auction_start_price: None,
    auction_end_price: None,
};

ModifyOrderParams

Parameters for modifying an existing order. All fields are optional - only specified fields will be updated.

Fields

direction
Option<PositionDirection>
Update order direction
base_asset_amount
Option<u64>
Update base asset amount
price
Option<u64>
Update limit price
reduce_only
Option<bool>
Update reduce-only flag
post_only
Option<PostOnlyParam>
Update post-only behavior
bit_flags
Option<u8>
Update bit flags
max_ts
Option<i64>
Update maximum timestamp
trigger_price
Option<u64>
Update trigger price
trigger_condition
Option<OrderTriggerCondition>
Update trigger condition
oracle_price_offset
Option<i32>
Update oracle price offset
auction_duration
Option<u8>
Update auction duration
auction_start_price
Option<i64>
Update auction start price
auction_end_price
Option<i64>
Update auction end price
policy
Option<u8>
Modification policy

Example

use drift_rs::types::ModifyOrderParams;

// Modify only the price of an existing order
let modify_params = ModifyOrderParams {
    price: Some(105_000_000), // Update to $105
    ..Default::default()
};

Enums

OrderType

pub enum OrderType {
    Market,
    Limit,
    TriggerMarket,
    TriggerLimit,
    Oracle,
}

OrderStatus

pub enum OrderStatus {
    Init,
    Open,
    Filled,
    Cancelled,
}

PostOnlyParam

pub enum PostOnlyParam {
    None,           // No post-only requirement
    MustPostOnly,   // Order must be posted as maker
    TryPostOnly,    // Try to post, cancel if taker
    Slide,          // Slide price to avoid taking
}

OrderTriggerCondition

pub enum OrderTriggerCondition {
    Above,
    Below,
    TriggeredAbove,
    TriggeredBelow,
}

Build docs developers (and LLMs) love