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.
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.
Limit Order - A limit order indicates your intent to buy or sell a given asset at the
priceyou specify in yourOrderParams.Trigger Market Order - A trigger market order indicates that once the price of the base asset satisfies your
trigger_priceandtrigger_condition, that your trigger order should be converted to a market order at the current market price.Trigger Limit Order - A trigger limit order indicates that once the price of the base asset satisfies your
trigger_priceandtrigger_condition, that your trigger order should be converted to a market order to be executed at thepriceyou specify.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] = NoneHere's what each of these means:
order_type - The type of order you intend to place.
OrderTypes described above.base_asset_amount - The amount of the base asset you intend to buy or sell in this order. Scaled by
BASE_PRECISION, or1e6.market_index - The index of the market for which you are placing this order. For example, the SOL-PERP perp market index is 0.
direction - The direction of the order.
PositionDirection.Long()orPositionDirection.Short().market_type - The type of market on which this order will be placed.
MarketType.Perp()orMarketType.Spot().user_order_id - You can set a custom
inthere to decide what orders to cancel or update later. Usually, it's fine to leave it blank / 0.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, or1e6.reduce_only - A boolean representing whether or not the order is intended to strictly reduce a position or not.
post_only - A
PostOnlyParamsobject enforcing whether or not this order is intended to provide liquidity the pool for a 0% exchange fee. Without a non-NONEPostOnlyParamhere, orders that don't execute immediately are not post-only.PostOnlyParams.MustPostOnly(),PostOnlyParams.TryPostOnly(),PostOnlyParams.Slide(),PostOnlyParams.NONE().immediate_or_cancel - A
boolrepresenting 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 abase_asset_amountof 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).max_ts - The maximum timestamp at which this order is valid.
trigger_price - For trigger orders, this is the price at which the trigger should activate. Scaled by
PRICE_PRECISION, or1e6.trigger_condition - The condition under which a trigger order will activate.
TriggerCondition.Above()orTriggerCondition.Below().oracle_price_offset - If you are placing an oracle order, this is the offset from the oracle at which you intend
auction_duration - The number of slots that this order will be in an auction for.
auction_start_price - The starting price of the auction. Scaled by
PRICE_PRECISION, or1e6.auction_end_price - The ending price of the auction. Scaled by
PRICE_PRECISION, or1e6.
Orders
You can place an order with your OrderParams , but here's what the actual Order class looks like:
Last updated