Orders

The Orders API allows a user to 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 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.

For further details on order functionality, please see the Trading On Alpaca - Orders page.

Please note that body parameters should be passed using a JSON encoded body.

[GET] Get a list of orders

GET/v2/orders
Retrieves a list of orders for the account, filtered by the supplied query parameters.

Parameters

Query Parameters

status
string
Order status to be queried. open, closed or all. Defaults to open.
limit
int
The maximum number of orders in response. Defaults to 50 and max is 500.
after
timestamp
The response will include only ones submitted after this timestamp (exclusive.)
until
timestamp
The response will include only ones submitted until this timestamp (exclusive.)
direction
string
The chronological order of response based on the submission time. asc or desc. Defaults to desc.
nested
boolean
If true, the result will roll up multi-leg orders under the legs field of primary order.

Response

An array of Order object

[POST] Request a new order

POST/v2/orders
Places a new order for the given account. An order request may be rejected if the account is not authorized for trading, or if the tradable balance is insufficient to fill the order.

Parameters

Body Parameters

symbol
stringRequired
symbol or asset ID to identify the asset to trade
qty
string<int>Required
number of shares to trade
side
stringRequired
buy or sell
type
stringRequired
market, limit, stop, stop_limit, or trailing_stop
time_in_force
stringRequired
day, gtc, opg, cls, ioc, fok. Please see Understand Orders for more info.
limit_price
string<number>Required
required if type is limit or stop_limit
stop_price
string<number>Required
required if type is stop or stop_limit
trail_price
string<number>Required
this or trail_percent is required if type is trailing_stop
trail_percent
string<number>Required
this or trail_price is required if type is trailing_stop
extended_hours
boolean
(default) false. If true, order will be eligible to execute in premarket/afterhours. Only works with type limit and time_in_force day.
client_order_id
string (<= 48 characters)
A unique identifier for the order. Automatically generated if not sent.
order_class
string
simple, bracket, oco or oto. For details of non-simple order classes, please see Bracket Order Overview
take_profit
object
Additional parameters for take-profit leg of advanced orders
limit_price
string<number>Required
required for bracket orders
stop_loss
object
Additional parameters for stop-loss leg of advanced orders
stop_price
string<number>Required
required for bracket orders
limit_price
string<number>
the stop-loss order becomes a stop-limit order if specified

Response

The new Order object

Errors

403 Forbidden
Buying power or shares is not sufficient.
422 Unprocessable
Input parameters are not recognized.

[GET] Get an order

GET/v2/orders/{order_id}
Retrieves a single order for the given order_id.

Parameters

Path Parameters

order_id
string<uuid>
Order ID

Query Parameters

nested
boolean
If true, the result will roll up multi-leg orders under the legs field of primary order.

Response

The requested Order object

Errors

404 Not found
Order is not found.

[GET] Get an order by client order id

GET/v2/orders:by_client_order_id
Retrieves a single order for the given client_order_id.

Response

The requested Order object

Errors

404 Not found
Order is not found.

[PATCH] Replace an order

PATCH/v2/orders/{order_id}

Replaces a single order with updated parameters. Each parameter overrides the corresponding attribute of the existing order. The other attributes remain the same as the existing order.

A success return code from a replaced order does NOT guarantee the existing open order has been replaced. If the existing open order is filled before the replacing (new) order reaches the execution venue, the replacing (new) order is rejected, and these events are sent in the trade_updates stream channel. Read more about the trade stream updates here.

While an order is being replaced, buying power is reduced by the larger of the two orders that have been placed (the old order being replaced, and the newly placed order to replace it). If you are replacing a buy entry order with a higher limit price than the original order, the buying power is calculated based on the newly placed order. If you are replacing it with a lower limit price, the buying power is calculated based on the old order.

Parameters

Path Parameters

order_id
string<uuid>
Order ID

Body Parameters

qty
string<int>
number of shares to trade
time_in_force
string
day, gtc, opg, cls, ioc, fok. Please see Understand Orders for more info.
limit_price
string<number>
required if type is limit or stop_limit
stop_price
string<number>
required if type is stop or stop_limit
trail
string<number>
the new value of the trail_price or trail_percent value (works only for type="trailing_stop”)
client_order_id
string (<= 48 characters)
A unique identifier for the order. Automatically generated if not sent.

Response

The new Order object with the new order ID.

Errors

403 Forbidden
Buying power or shares is not sufficient.
422 Unprocessable
Input parameters are not recognized.

[DELETE] Cancel all orders

DELETE/v2/orders
Attempts to cancel all open orders. A response will be provided for each order that is attempted to be cancelled. If an order is no longer cancelable, the server will respond with status 500 and reject the request.

Response

HTTP 207 Multi-Status with body; an array of objects that include the order id and http status code for each status request.

Errors

500
Failed to cancel order.

[DELETE] Cancel an order

DELETE/v2/orders/{order_id}
Attempts to cancel an open order. If the order is no longer cancelable (example: status="filled"), the server will respond with status 422, and reject the request. Upon acceptance of the cancel request, it returns status 204.

Parameters

Path Parameters

order_id
string<uuid>
Order ID

Response

Errors

404 Not found
Order is not found.
422 Unprocessable
The order status is not cancelable.

Order Entity

Example

{
  "id": "904837e3-3b76-47ec-b432-046db621571b",
  "client_order_id": "904837e3-3b76-47ec-b432-046db621571b",
  "created_at": "2018-10-05T05:48:59Z",
  "updated_at": "2018-10-05T05:48:59Z",
  "submitted_at": "2018-10-05T05:48:59Z",
  "filled_at": "2018-10-05T05:48:59Z",
  "expired_at": "2018-10-05T05:48:59Z",
  "canceled_at": "2018-10-05T05:48:59Z",
  "failed_at": "2018-10-05T05:48:59Z",
  "replaced_at": "2018-10-05T05:48:59Z",
  "replaced_by": "904837e3-3b76-47ec-b432-046db621571b",
  "replaces": null,
  "asset_id": "904837e3-3b76-47ec-b432-046db621571b",
  "symbol": "AAPL",
  "asset_class": "us_equity",
  "qty": "15",
  "filled_qty": "0",
  "type": "market",
  "side": "buy",
  "time_in_force": "day",
  "limit_price": "107.00",
  "stop_price": "106.00",
  "filled_avg_price": "106.00",
  "status": "accepted",
  "extended_hours": false,
  "legs": null,
  "trail_price": "1.05",
  "trail_percent": null,
  "hwm": "108.05"
}

Properties

id
string<uuid>
Order id
client_order_id
string
Client unique order id
created_at
string<timestamp>
updated_at
string<timestamp> (Nullable)
submitted_at
string<timestamp> (Nullable)
filled_at
string<timestamp> (Nullable)
expired_at
string<timestamp> (Nullable)
canceled_at
string<timestamp> (Nullable)
failed_at
string<timestamp> (Nullable)
replaced_at
string<timestamp> (Nullable)
replaced_by
string<uuid> (Nullable)
The order ID that this order was replaced by
replaces
string<uuid> (Nullable)
The order ID that this order replaces
asset_id
string<uuid>
Asset ID
symbol
string
Asset symbol
asset_class
string
Asset class
qty
string<number>
Ordered quantity
filled_qty
string<number>
Filled quantity
type
string<order_type>
Valid values: market, limit, stop, stop_limit, trailing_stop
side
string<side>
Valid values: buy, sell
time_in_force
string<time_in_force>
limit_price
string<number> (Nullable)
Limit price
stop_price
string<number> (Nullable)
Stop price
filled_avg_price
string<number> (Nullable)
Filled average price
status
string<order_status>
extended_hours
boolean
If true, eligible for execution outside regular trading hours.
legs
array<Order>
When querying non-simple order_class orders in a nested style, an array of Order entities associated with this order. Otherwise, null.
trail_price
string<number>
The dollar value away from the high water mark for trailing stop orders.
trail_percent
string<number>
The percent value away from the high water mark for trailing stop orders.
hwm
string<number>
The highest (lowest) market price seen since the trailing stop order was submitted.