Understand Orders

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.

Order Types

When you submit an order, you can choose one of supported order types. Currently, Alpaca supports four different types of orders.

Market Order

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.

Limit Order

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.

Stop Order

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.

  • day
    The order is good for the day, and it will be canceled automatically at the end of market hours.
  • gtc
    The order is good until canceled.
  • opg
    The order is placed at the time the market opens.

Order Lifecycle

An order executed through Alpaca can experience several status changes during its lifecycle. These most common statuses are described in detail below:

  • new
    The order has been received by Alpaca, and routed to exchanges for execution. This is the usual initial state of an order.
  • partially_filled
    The order has been partially filled.
  • filled
    The order has been filled, and no further updates will occur for the order.
  • done_for_day
    The order is done executing for the day, and will not receive further updates until the next trading day.
  • canceled
    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.
  • expired
    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:

  • accepted
    The order has been received by Alpaca, but hasn’t yet been routed to exchanges. This state only occurs on rare occasions.
  • pending_new
    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.
  • accepted_for_bidding
    The order has been received by exchanges, and is evaluated for pricing. This state only occurs on rare occasions.
  • pending_cancel
    The order is waiting to be canceled. This state only occurs on rare occasions.
  • stopped
    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.
  • rejected
    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.
  • suspended
    The order has been suspended, and is not eligible for trading. This state only occurs on rare occasions.
  • calculated
    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 filled, canceled, or expired.