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 attached to entry orders and execute when the specified price levels are reached. When you attach TP and SL orders to an entry order, 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. Take-profit and stop-loss orders apply to the order quantity they’re attached to. This allows you to place multiple TP/SL orders for different portions of your position. When the trigger price of an individual TP or SL order is reached, the corresponding order quantity is closed via either a market or limit order, and the opposite order (SL or TP) is automatically canceled. Additionally, you can modify the TP/SL prices before the parent order is filled. TP and SL orders always have the opposite side compared to their parent order. For example:- A buy order is protected by a sell take-profit order and a sell stop-loss order.
- A sell order is protected by a buy take-profit order and a buy stop-loss order.
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.