pub struct Order {Show 14 fields
pub id: String,
pub asset_class: String,
pub client_order_id: String,
pub is_extended_hours: bool,
pub filled_qty: u32,
pub filled_avg_price: Option<f64>,
pub limit_price: Option<f64>,
pub order_type: OrderType,
pub qty: u32,
pub side: OrderSide,
pub status: OrderStatus,
pub stop_price: Option<f64>,
pub symbol: String,
pub time_in_force: TimeInForce,
}
Expand description
A unique order in the system.
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.
Fields§
§id: String
Order ID - a UUID
asset_class: String
Asset class
client_order_id: String
Client unique order id
is_extended_hours: bool
If true, eligible for execution outside regular trading hours.
filled_qty: u32
Filled quantity
filled_avg_price: Option<f64>
Filled average price
limit_price: Option<f64>
Limit price
order_type: OrderType
Type of order
qty: u32
Ordered quantity
side: OrderSide
Direction of trade - buy or sell
status: OrderStatus
The status of the order
stop_price: Option<f64>
§symbol: String
Asset symbol
time_in_force: TimeInForce
how long the order is open for
Implementations§
Source§impl Order
impl Order
Sourcepub async fn cancel(&self, alpaca: &Alpaca) -> Result<()>
pub async fn cancel(&self, alpaca: &Alpaca) -> Result<()>
Attempts to cancel this order. If the order is no longer cancelable (example: status=order_filled), an error will be generated.
§Example
To cancel an open order:
let alpaca = Alpaca::live("KEY_ID", "SECRET").await.unwrap();
let open_order = ...; // some buy
open_order.cancel().await?;
Sourcepub fn update(&self) -> OrderUpdater
pub fn update(&self) -> OrderUpdater
Attempts to replace this open order. Will fail if the order is not open or the user does not have enough buying power to execute it.
§Example
To update the limit price of an open order to $100.0:
let alpaca = Alpaca::live("KEY_ID", "SECRET").await.unwrap();
let open_order = ...; // some buy
open_order.update()
.limit_price(100.0)
.place(&alpaca).await.unwrap();
Sourcepub async fn get_open(alpaca: &Alpaca) -> Result<Vec<Order>>
pub async fn get_open(alpaca: &Alpaca) -> Result<Vec<Order>>
Gets a list of all open orders - returns an empty vector if there are no open orders
Sourcepub fn buy(
symbol: &str,
qty: u32,
order_type: OrderType,
time_in_force: TimeInForce,
) -> OrderBuilder
pub fn buy( symbol: &str, qty: u32, order_type: OrderType, time_in_force: TimeInForce, ) -> OrderBuilder
Requests a new ‘buy’ order.
§Example
To buy 100 shares of AAPL at a limit price of $100.0 before the end of today:
let alpaca = Alpaca::live("KEY_ID", "SECRET").await.unwrap();
let order = Order::buy("AAPL", 100, OrderType::Limit, TimeInForce::DAY)
.limit_price(100.0)
.place(&alpaca).await.unwrap();
Sourcepub fn sell(
symbol: &str,
qty: u32,
order_type: OrderType,
time_in_force: TimeInForce,
) -> OrderBuilder
pub fn sell( symbol: &str, qty: u32, order_type: OrderType, time_in_force: TimeInForce, ) -> OrderBuilder
Requests a new ‘sell’ order.
§Example
To sell 100 shares of MSFT at market price before the end of today:
let alpaca = Alpaca::live("KEY_ID", "SECRET").await.unwrap();
let order = Order::sell("MSFT", 100, OrderType::Market, TimeInForce::DAY)
.place(&alpaca).await.unwrap();