Order is a lightweight object that describes the desired side, size, and other order parameters. The results of order execution are reflected in its status. The trading interface provides special functions for managing orders: place_order, amend_order, and cancel_order.
These order management methods implement the builder pattern and are used like this:
cancel_order does not require an explicit submit call, as it has no settings.
More detailed information about these methods can be found in library reference.
Order types, parameters, and execution logic
Market
A market order is an instruction from an investor to a broker to buy or sell shares, bonds, or other assets at the best price currently available in the market. For most investors and most situations, this is the standard way to place a trade. When the asset is highly liquid — such as a major large-cap stock or a widely traded ETF — there are typically many buyers and sellers active at any given moment. As a result, a market order is usually executed almost immediately (subject to processing delays), and the final price is generally very close to the most recent quote visible to the investor. This is the simplest type of order. To place one, you only need to specify the order’s direction and size:side(indie.strategies.order_side):BUYorSELL;size: positive absolute quantity of asset to buy or sell;
Limit
Limit orders allow you to control the exact price at which you buy or sell a stock. A buy limit order sets the maximum price you’re willing to pay, while a sell limit order defines the minimum price you’re willing to accept. These orders are especially useful when trading:- Highly volatile stocks with large price swings
- Low-liquid stocks with wide bid-ask spreads
- Periods of market uncertainty or rapid price changes
- Situations where achieving a specific price is more important than immediate execution
limit: limit price, the order will execute at this price or better;
Stop
A stop order is used either to limit potential losses or to initiate a trade when the market reaches a specified price level. A buy stop order is typically used when a trader wants to buy an asset at a price higher than the current market value. Traders use buy stop orders when they expect the price to continue rising after breaking through a resistance level. A buy stop order allows traders to automatically open a long position once the price exceeds a specified level, potentially capturing further upward movement. A sell stop order is used when a trader wants to sell an asset at a price lower than the current market value. Traders typically use sell stop orders to protect against further losses if the price breaks below a support level. When triggered, a sell stop order automatically exits the position to reduce potential losses and manage risk. To create a stop order, you must specify the stop price:stop: the stop (trigger) price. A buy stop triggers when the market reaches this price or higher; a sell stop triggers when the market reaches this price or lower.direction(optional): the trigger direction for the stop price. Possible values:trigger_direction.AUTO(default): the system automatically determines the trigger direction based on the current market price and the specified stop price. If the stop price is above the current market price, it triggers when the price rises to it; if below, it triggers when the price falls to it.trigger_direction.RISES_TO: the stop order triggers when the market price rises to or above the stop price.trigger_direction.FALLS_TO: the stop order triggers when the market price falls to or below the stop price.
Stop-limit
A stop-limit order is a conditional order that combines the features of a stop order and a limit order. It gives traders more control over execution by allowing them to specify both a stop price and a limit price. When the market reaches the stop price, the order is activated and converted into a limit order, which will execute at the specified limit price or better. The stop price in a stop-limit order serves as an activation point or trigger. For a sell stop-limit order, the trigger activates when the market reaches or falls below the stop price. For a buy stop-limit order, it activates when the market reaches or rises above the stop price. To create a stop-limit order, you must specify both the stop and limit prices:stop: the stop (trigger) price. A buy stop triggers at this price or higher; a sell stop triggers at this price or lower;limit: the limit price. After triggering, the order will execute at this price or better;
Take-profit and stop-loss orders
Take-profit (TP) and stop-loss (SL) orders are risk management tools that help traders automatically close positions to secure profits or limit losses. These orders are specified on entry orders and, once the entry is filled, become independent stop orders that protect the entire position.Position-level behavior
TP and SL operate at the position level, not at the individual order level:- Size tracks the position. The size of TP and SL orders always equals the current position size. If the position grows or shrinks (due to additional entries or partial closes), the TP and SL sizes are automatically adjusted.
- At most one TP and one SL. There can be at most one active take-profit and one active stop-loss order at any time. If a new entry order specifies TP/SL prices, the existing TP/SL prices are updated rather than creating additional orders. If a new entry order does not specify TP/SL prices, the existing TP/SL orders remain unchanged.
- Cancellation on position close. If the position is fully closed by any other order (not by TP/SL themselves), the TP and SL orders are automatically canceled.
- Cancellation on position reversal. If the position reverses direction (e.g. from long to short), the existing TP and SL orders are canceled. If the reversing order specifies new TP/SL prices, new TP/SL orders are created for the reversed position.
OCO bracket
When both TP and SL are active, they work together as a bracket (also known as OCO — One-Cancels-Other): when one of them executes, the other is automatically canceled. This ensures that only one exit occurs per position. TP and SL orders always have the opposite side compared to the position they protect. For example:- A long position is protected by a sell take-profit order and a sell stop-loss order.
- A short position is protected by a buy take-profit order and a buy stop-loss order.
Syntax
To create orders with take-profit and stop-loss, you must specify the TP and/or SL prices. These prices serve as the stop price for the exit orders that will be placed after the parent order is executed. Additionally, you can set a limit price for TP/SL orders, which converts them into stop-limit orders:Statuses and lifecycle
The order statuses are:CREATED— created locally but not yet sent to the exchange emulator;PLACED— accepted by the exchange and entered the order book;PENDING_PLACED— waiting for a trigger condition to be met and has not yet entered the order book;PARTIALLY_FILLED— partially filled and remains open;FILLED— fully executed;PARTIALLY_FILLED_CLOSED— partially filled and then closed without full execution;REJECTED— rejected by the exchange or by margin checks;CANCELED— canceled by user.