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
Parameters
Query Parameters
open
, closed
or all
.
Defaults to open
.asc
or desc
. Defaults to desc
.legs
field of primary order.Response
An array of Order object[POST] Request a new order
Parameters
Body Parameters
market
and day
order types.qty
. Can only work for market
order types and day
for time in force.buy
or sell
market
, limit
, stop
, stop_limit
, or trailing_stop
limit
or stop_limit
stop
or stop_limit
trail_percent
is required if type is trailing_stop
trail_price
is required if type is trailing_stop
limit
and time_in_force day
.simple
, bracket
, oco
or oto
. For details of non-simple order classes,
please see Bracket Order OverviewResponse
The new Order objectErrors
[GET] Get an order
order_id
.
Parameters
Path Parameters
Query Parameters
legs
field of primary order.Response
The requested Order objectErrors
[GET] Get an order by client order id
client_order_id
.
Parameters
Query Parameters
Response
The requested Order objectErrors
[PATCH] Replace an order
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
Body Parameters
limit
or stop_limit
stop
or stop_limit
trail_price
or trail_percent
value (works only for type="trailing_stop”)Response
The new Order object with the new order ID.Errors
[DELETE] Cancel all orders
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
[DELETE] Cancel an order
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
Response
Errors
Order Entity
Example
{
"id": "61e69015-8549-4bfd-b9c3-01e75843f47d",
"client_order_id": "eb9e2aaa-f71a-4f51-b5b4-52a6c565dad4",
"created_at": "2021-03-16T18:38:01.942282Z",
"updated_at": "2021-03-16T18:38:01.942282Z",
"submitted_at": "2021-03-16T18:38:01.937734Z",
"filled_at": null,
"expired_at": null,
"canceled_at": null,
"failed_at": null,
"replaced_at": null,
"replaced_by": null,
"replaces": null,
"asset_id": "b0b6dd9d-8b9b-48a9-ba46-b9d54906e415",
"symbol": "AAPL",
"asset_class": "us_equity",
"notional": "500",
"qty": null,
"filled_qty": "0",
"filled_avg_price": null,
"order_class": "",
"order_type": "market",
"type": "market",
"side": "buy",
"time_in_force": "day",
"limit_price": null,
"stop_price": null,
"status": "accepted",
"extended_hours": false,
"legs": null,
"trail_percent": null,
"trail_price": null,
"hwm": null
}
Properties
qty
will be null. Can take up to 9 decimal points.notional
will be null. Can take up to 9 decimal points.simple
, bracket
, oco
or oto
. For details of non-simple order classes,
please see Bracket Order Overviewtype
field below.)market
, limit
, stop
, stop_limit
, trailing_stop
buy
, sell