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.
In order to accept your orders that would open new positions or add to existing ones, your account must have sufficient buying power. Alpaca applies a “buying” power check to both buy long and sell short positions.
The calculated value of an opening buy order is the order’s limit price multiplied by the order’s quantity. In the case of market buy orders, the limit price is 2.5% to 4% above the current market price as noted above.
The calculated value of an opening sell short order is MAX(order’s limit price, 3% above the current ask price) multiplied by the order’s quantity. In the case of market short orders, the value is simply 3% above the current ask price * order quantity.
The order’s calculated value is then checked against your available buying power to determine if it can be accepted. Please note that your available buying power is reduced by your existing open buy long and sell short orders, whereas your sell long and buy to cover orders do not replenish your available buying power until they have executed.
For example, if your buying power is $10,000 and you submit a limit buy order with an order value of $3,000, your order will be accepted and your remaining available buying power will be $7,000. Even if this order is unfilled, as long as it is open and has not been cancelled, it will count against your available buying power. If you then submitted another order with an order value of $8,000, it would be rejected.
Orders Submitted Outside of Eligible Trading Hours
Orders submitted outside of Regular Trading Hours (9:30am - 4:00pm ET) that are not eligible to be executed during extended hours will be queued and eligible for execution at the time of the next market open.
Orders eligible for extended hours submitted outside of 9:00am - 6:00pm ET are handled as described in the section below.
Extended Hours Trading
Using API v2 (only available to ETC accounts), you can submit and fill orders during pre-market and after-hours. This feature is not available to legacy accounts or those using API v1. Extended hours trading has specific risks due to the less liquidity. Please read through our disclosure for more details.
Currently, we supported the following extended hours:
Pre-market: 9:00 - 9:30am
After-hours: 4:00 - 6:00pm
Additionally, please be aware of the following constraints.
- If the order is submitted between 6:00pm and 8:00pm ET on a market day, the order request is returned with error. Alpaca reserves this time window for future expansion of supported hours.
- If the order is submitted after 8:00pm but before 9:00am ET of the following trading day, the order request is queued and will be eligible for execution from the beginning of the next available supported pre-market hours at 9:00am.
Submitting an Extended Hours Eligible Order
To indicate an order is eligible for extended hours trading, you need to supply a boolean
extended_hours to your order request. By setting this parameter as true, the order is will be
eligible to execute in the pre-market or after-hours.
day orders will be accepted as extended hours eligible. All other order types and TIFs will be rejected
with an error. You must adhere to these settings in order to participate in extended hours:
1) The order type must be set to
limit (with limit price). Any other type of orders will be rejected with an error.
2) Time-in-force must be set to be
day. Any other time-in-force will be rejected with an error.
All symbols supported during regular market hours are also supported during extended hours. Short selling is also treated the same.
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 currently available market price. It provides the most likely method of filling an order. Market orders fill nearly instantaneously.
As a trade-off, your fill price may slip depending on the available liquidity at each price level as well as any price moves that may occur while your order is being routed to its execution venue. There is also the risk with market orders that they may get filled at unexpected prices due to short-term price spikes.
Alpaca uses the following rounding mechanics with respect to buy orders: (1) rounded down to two decimal places if the last trade price is over $1.00; otherwise, rounded down to four decimal places.
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 slippage, it may not be filled for a quite a bit of time, if at all. For a buy limit order, if the market price is within your specified limit price, you can expect the order to be filled. If the market price is equivalent to your limit price, your order may or may not be filled; if the order cannot immediately execute against resting liquidity, then it is deemed non-marketable and will only be filled once a marketable order interacts with it. You could miss a trading opportunity if price moves away from the limit price before your order can be filled.
Hyper-marketable Limit Order Rejection A limit orders with a limit price that significantly exceeds the current market price will be rejected as part of our risk checks to mitigate against “fat finger” errors. We currently use exchange guidelines for erroneous trades to determine the thresholds at which orders are rejected:
|Greater than $0.00 up to and including $25.00||10%|
|Greater than $25.00 up to and including $50.00||5%|
|Greater than $50.00||3%|
The thresholds are doubled during pre-market and after-hours.
A stop (market) 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 market price crosses the specified stop price, the stop order becomes a market order. Alpaca converts buy stop orders into svtop limit orders with a limit price that is 4% higher than a stop price < $50 (or 2.5% higher than a stop price >= $50). Sell stop orders are not converted into stop limit orders.
A stop order does not guarantee the order will be filled at a certain price after it is 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 a stop order with those of a limit order and is used to mitigate risk. The stop-limit order will be executed at a specified limit 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.
Opening and Closing Auction Orders
Market on open and limit on open orders are only eligible to execute in the opening auction. Market on close and limit on close orders are only eligible to execute in the closing auction. Please see the Time in Force section for more details.
Advanced Order Types
Advanced order types such as OCO(one-cancels-the-other) and trailing stop are coming soon. Stay tuned!
Time in Force
Alpaca supports the following Time-In-Force designations:
A day order is eligible for execution only on the day it is live. By default, the order is only valid during Regular Trading Hours (9:30am - 4:00pm ET). If unfilled after the closing auction, it is automatically canceled. If submitted after the close, it is queued and submitted the following trading day. However, if marked as eligible for extended hours, the order can also execute during supported extended hours.
The order is good until canceled. Non-marketable GTC limit orders are subject to price adjustments to offset corporate actions affecting the issue. We do not currently support Do Not Reduce(DNR) orders to opt out of such price adjustments.
Use this TIF with a market/limit order type to submit “market on open” (MOO) and “limit on open” (LOO) orders. This order is eligible to execute only in the market opening auction. Any unfilled orders after the open will be cancelled. OPG orders submitted after 9:28am but before 7:00pm ET will be rejected. OPG orders submitted after 7:00pm will be queued and routed to the following day’s opening auction.
On open/on close orders are routed to the primary exchange. Such orders do not necessarily execute exactly at 9:30am / 4:00pm ET but execute per the exchange’s auction rules.
Use this TIF with a market/limit order type to submit “market on close” (MOC) and “limit on close” (LOC) orders. This order is eligible to execute only in the market closing auction. Any unfilled orders after the close will be cancelled. CLS orders submitted after 3:50pm but before 7:00pm ET will be rejected. CLS orders submitted after 7:00pm will be queued and routed to the following day’s closing auction. Only available with API v2.
An Immediate Or Cancel (IOC) order requires all or part of the order to be executed immediately. Any unfilled portion of the order is canceled. Only available with API v2.
A Fill or Kill (FOK) order is only executed if the entire order quantity can be filled, otherwise the order is canceled. Only available with API v2.
An order executed through Alpaca can experience several status changes during its lifecycle. The 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 the execution venue. 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