Struct Order

Source
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

Source

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

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

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

Source

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

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

Trait Implementations§

Source§

impl Debug for Order

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Order

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations§

§

impl Freeze for Order

§

impl RefUnwindSafe for Order

§

impl Send for Order

§

impl Sync for Order

§

impl Unpin for Order

§

impl UnwindSafe for Order

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

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

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T