[][src]Struct alpaca_finance::Order

pub struct Order {
    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,
}

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

impl Order[src]

pub async fn cancel<'_, '_>(&'_ self, alpaca: &'_ Alpaca) -> Result<()>[src]

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?;

pub fn update(&self) -> OrderUpdater[src]

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();

pub async fn get_open<'_>(alpaca: &'_ Alpaca) -> Result<Vec<Order>>[src]

Gets a list of all open orders - returns an empty vector if there are no open orders

pub fn buy(
    symbol: &str,
    qty: u32,
    order_type: OrderType,
    time_in_force: TimeInForce
) -> OrderBuilder
[src]

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();

pub fn sell(
    symbol: &str,
    qty: u32,
    order_type: OrderType,
    time_in_force: TimeInForce
) -> OrderBuilder
[src]

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();

Trait Implementations

impl Debug for Order[src]

impl<'de> Deserialize<'de> for Order[src]

Auto Trait Implementations

impl RefUnwindSafe for Order

impl Send for Order

impl Sync for Order

impl Unpin for Order

impl UnwindSafe for Order

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,