The Order Class

This page discusses the Order object in DriftPy.

Types of Orders

There are several different types of orders that you can place on Drift. Here's what they are and what they mean.

  1. Market Order - A market order is the simplest type of order and indicates your intent to buy or sell a given asset at the current market price.

  2. Limit Order - A limit order indicates your intent to buy or sell a given asset at the price you specify in your OrderParams .

  3. Trigger Market Order - A trigger market order indicates that once the price of the base asset satisfies your trigger_price and trigger_condition, that your trigger order should be converted to a market order at the current market price.

  4. Trigger Limit Order - A trigger limit order indicates that once the price of the base asset satisfies your trigger_price and trigger_condition , that your trigger order should be converted to a market order to be executed at the price you specify.

  5. Oracle / Oracle Offset Order - An oracle offset order is a special type of limit order that pegs your entry price to the reported oracle price + your specified offset.

Order Params

To place an order, you need to declare OrderParams indicating your intents with that order. The OrderParams class looks like this:

@dataclass
class OrderParams:
    order_type: OrderType
    base_asset_amount: int
    market_index: int
    direction: PositionDirection 
    market_type: MarketType = None
    user_order_id: int = 0
    price: int = 0
    reduce_only: bool = False
    post_only: PostOnlyParams = field(default_factory=PostOnlyParams.NONE)
    immediate_or_cancel: bool = False
    max_ts: Optional[int] = None
    trigger_price: Optional[int] = None
    trigger_condition: OrderTriggerCondition = field(
        default_factory=OrderTriggerCondition.Above
    )
    oracle_price_offset: Optional[int] = None
    auction_duration: Optional[int] = None
    auction_start_price: Optional[int] = None
    auction_end_price: Optional[int] = None

Here's what each of these means:

  1. order_type - The type of order you intend to place. OrderType s described above.

  2. base_asset_amount - The amount of the base asset you intend to buy or sell in this order. Scaled by BASE_PRECISION , or 1e6.

  3. market_index - The index of the market for which you are placing this order. For example, the SOL-PERP perp market index is 0.

  4. direction - The direction of the order. PositionDirection.Long() or PositionDirection.Short() .

  5. market_type - The type of market on which this order will be placed. MarketType.Perp() or MarketType.Spot() .

  6. user_order_id - You can set a custom int here to decide what orders to cancel or update later. Usually, it's fine to leave it blank / 0.

  7. price - For market orders, always leave this at 0. For limit orders, this is the price at which the order will execute. Scaled by PRICE_PRECISION, or 1e6.

  8. reduce_only - A boolean representing whether or not the order is intended to strictly reduce a position or not.

  9. post_only - A PostOnlyParams object enforcing whether or not this order is intended to provide liquidity the pool for a 0% exchange fee. Without a non-NONE PostOnlyParam here, orders that don't execute immediately are not post-only. PostOnlyParams.MustPostOnly(), PostOnlyParams.TryPostOnly(), PostOnlyParams.Slide(), PostOnlyParams.NONE().

  10. immediate_or_cancel - A bool representing whether or not this order should attempt to fill as much as it can immediately and cancel whatever surplus it cannot fill. For example, if you place an IOC order with a base_asset_amount of 100, and only 75 can be filled immediately, the surplus 25 will be canceled. This is only applicable to Place and Take or Place and Make orders (discussed in detail in Placing an Order > Place and Orders).

  11. max_ts - The maximum timestamp at which this order is valid.

  12. trigger_price - For trigger orders, this is the price at which the trigger should activate. Scaled by PRICE_PRECISION , or 1e6.

  13. trigger_condition - The condition under which a trigger order will activate. TriggerCondition.Above() or TriggerCondition.Below().

  14. oracle_price_offset - If you are placing an oracle order, this is the offset from the oracle at which you intend

  15. auction_duration - The number of slots that this order will be in an auction for.

  16. auction_start_price - The starting price of the auction. Scaled by PRICE_PRECISION , or 1e6.

  17. auction_end_price - The ending price of the auction. Scaled by PRICE_PRECISION , or 1e6.

Orders

You can place an order with your OrderParams , but here's what the actual Order class looks like:

@dataclass
class Order:
    slot: int
    price: int
    base_asset_amount: int
    base_asset_amount_filled: int
    quote_asset_amount_filled: int
    trigger_price: int
    auction_start_price: int
    auction_end_price: int
    max_ts: int
    oracle_price_offset: int
    order_id: int
    market_index: int
    status: OrderStatus
    order_type: OrderType
    market_type: MarketType
    user_order_id: int
    existing_position_direction: PositionDirection
    direction: PositionDirection
    reduce_only: bool
    post_only: bool
    immediate_or_cancel: bool
    trigger_condition: OrderTriggerCondition
    auction_duration: int
    padding: list[int]

Last updated