Using Alpaca Trade API, a user can monitor, place and cancel their orders with Alpaca. Each order has a unique identifier provided by the client. This client-side unique order ID will be automatically generated by the system if not provided by the client, and will be returned as part of the order object along with the rest of the fields described below. Once an order is placed, it can be queried using the client-side order ID or system-assigned unique ID to check the status. Updates on open orders at Alpaca will also be sent over the streaming interface, which is the recommended method of maintaining order state.
Orders Submitted Outside of Regular Trading Hours
Orders submitted outside of market hours will be routed and made available for execution at the time of the next market open. Extended-hours trading is not yet supported at Alpaca, but orders can be placed around the clock to be handled as soon as the market is open.
When you submit an order, you can choose one of supported order types. Currently, Alpaca supports four different types of orders.
A market order is a request to buy or sell a security at the current-available price in the current market. It provides the most likely method of filling.
If there is enough liquidity, market orders fill nearly instantaneously. However, with less liquid securities, it may still take some time.
As a trade-off, your filling price may slip depending on the market activities. There is also the risk with market orders that they may get filled at unexpected prices due to the short period price spikes.
A limit order is an order to buy or sell at a specified price or better. A buy limit order (a limit order to buy) is executed at the specified limit price or lower (i.e., better). Conversely, a sell limit order (a limit order to sell) is executed at the specified limit price or higher (better). Unlike a market order, you have to specify the limit price parameter when submitting your order.
While a limit order can prevent negative slippage, it may not get a fill for a quite a bit of time –- it will only be filled if price reaches the specified limit price level. You could miss a trading opportunity if price moves away from the limit price before your order can be filled. Note that even if the price moves to the limit price level, the order still may not get filled there are not enough buyers or sellers at that particular price level.
A stop order is an order to buy or sell a security when its price moves past a particular point, ensuring a higher probability of achieving a predetermined entry or exit price. Once the price crosses the predefined entry/exit point, the stop order becomes a market order.
A stop order does not guarantee the order will be filled at certain price after converted to a market order.
In order to submit a stop order, you will need to specify the stop price parameter in the API.
Stop Limit Order
A stop-limit order is a conditional trade over a set time frame that combines the features of stop with those of a limit order and is used to mitigate risk. The stop-limit order will be executed at a specified price, or better, after a given stop price has been reached. Once the stop price is reached, the stop-limit order becomes a limit order to buy or sell at the limit price or better.
In order to submit a stop limit order, you will need to specify both the limit and stop price parameters in the API.
Time in Force
The following are the types of time-in-force Alpaca supports.
The order is good for the day, and it will be canceled automatically at the end of market hours.
The order is good until canceled.
The order is placed at the time the market opens.
An order executed through Alpaca can experience several status changes during its lifecycle. These most common statuses are described in detail below:
The order has been received by Alpaca, and routed to exchanges for execution. This is the usual initial state of an order.
The order has been partially filled.
The order has been filled, and no further updates will occur for the order.
The order is done executing for the day, and will not receive further updates until the next trading day.
The order has been canceled, and no further updates will occur for the order. This can be either due to a cancel request by the user, or the order has been canceled by the exchanges due to its time-in-force.
The order has expired, and no further updates will occur for the order.
Less common states are described below. Note that these states only occur on very rare occasions, and most users will likely never see their orders reach these states:
The order has been received by Alpaca, but hasn’t yet been routed to exchanges. This state only occurs on rare occasions.
The order has been received by Alpaca, and routed to the exchanges, but has not yet been accepted for execution. This state only occurs on rare occasions.
The order has been received by exchanges, and is evaluated for pricing. This state only occurs on rare occasions.
The order is waiting to be canceled. This state only occurs on rare occasions.
The order has been stopped, and a trade is guaranteed for the order, usually at a stated price or better, but has not yet occurred. This state only occurs on rare occasions.
The order has been rejected, and no further updates will occur for the order. This state occurs on rare occasions, and may occur based on various conditions decided by the exchanges.
The order has been suspended, and is not eligible for trading. This state only occurs on rare occasions.
The order has been completed for the day (either filled or done for day), but remaining settlement calculations are still pending. This state only occurs on rare occasions.
An order may be canceled through the API up until the point it reaches
a state of either