#[non_exhaustive]pub struct OrderRequest { /* private fields */ }Expand description
Body of POST /accounts/{accountNumber}/orders (place) and
PUT /accounts/{accountNumber}/orders/{orderId} (replace). Construct
via OrderRequest::single (typestate builder) or via the
composite-strategy factories OrderRequest::oco and
OrderRequest::trigger.
Response-only fields (status, filledQuantity, enteredTime,
tag, requestedDestination, etc.) are not present here; they live
on Order instead.
Implementations§
Source§impl OrderRequest
impl OrderRequest
Sourcepub fn order_type(&self) -> Option<&OrderType>
pub fn order_type(&self) -> Option<&OrderType>
Order type (MARKET, LIMIT, STOP, NET_DEBIT, etc.).
Sourcepub fn complex_order_strategy_type(&self) -> Option<&ComplexOrderStrategyType>
pub fn complex_order_strategy_type(&self) -> Option<&ComplexOrderStrategyType>
Multi-leg option strategy shape, if any.
Sourcepub fn quantity(&self) -> Option<Decimal>
pub fn quantity(&self) -> Option<Decimal>
Top-level quantity, when Schwab carries it separately from the per-leg quantity.
Sourcepub fn stop_price(&self) -> Option<Decimal>
pub fn stop_price(&self) -> Option<Decimal>
Stop-trigger price for stop and stop-limit orders.
Sourcepub fn special_instruction(&self) -> Option<&SpecialInstruction>
pub fn special_instruction(&self) -> Option<&SpecialInstruction>
Special instruction (e.g. AllOrNone).
Sourcepub fn order_strategy_type(&self) -> Option<&OrderStrategyType>
pub fn order_strategy_type(&self) -> Option<&OrderStrategyType>
Envelope strategy (SINGLE, OCO, TRIGGER, …).
Sourcepub fn legs(&self) -> &[OrderLegRequest]
pub fn legs(&self) -> &[OrderLegRequest]
Order legs.
Sourcepub fn child_strategies(&self) -> &[OrderRequest]
pub fn child_strategies(&self) -> &[OrderRequest]
Child strategies of a composite envelope (OCO or TRIGGER).
Empty for SINGLE.
Source§impl OrderRequest
impl OrderRequest
Sourcepub fn single() -> SingleOrderBuilder<NeedsType>
pub fn single() -> SingleOrderBuilder<NeedsType>
Begin building a SINGLE strategy order. Defaults session=NORMAL
and duration=DAY; override with SingleOrderBuilder::session
and SingleOrderBuilder::duration on the Ready state.
Sourcepub fn buy_market(
symbol: impl Into<String>,
qty: impl IntoQuantity,
) -> SingleOrderBuilder<Ready>
pub fn buy_market( symbol: impl Into<String>, qty: impl IntoQuantity, ) -> SingleOrderBuilder<Ready>
Equity buy-at-market, default day order.
Sourcepub fn buy_limit(
symbol: impl Into<String>,
qty: impl IntoQuantity,
price: Decimal,
) -> SingleOrderBuilder<Ready>
pub fn buy_limit( symbol: impl Into<String>, qty: impl IntoQuantity, price: Decimal, ) -> SingleOrderBuilder<Ready>
Equity buy-at-limit, default day order.
Sourcepub fn sell_market(
symbol: impl Into<String>,
qty: impl IntoQuantity,
) -> SingleOrderBuilder<Ready>
pub fn sell_market( symbol: impl Into<String>, qty: impl IntoQuantity, ) -> SingleOrderBuilder<Ready>
Equity long-sale at market, default day order.
Sourcepub fn sell_limit(
symbol: impl Into<String>,
qty: impl IntoQuantity,
price: Decimal,
) -> SingleOrderBuilder<Ready>
pub fn sell_limit( symbol: impl Into<String>, qty: impl IntoQuantity, price: Decimal, ) -> SingleOrderBuilder<Ready>
Equity long-sale at limit, default day order.
Sourcepub fn sell_stop(
symbol: impl Into<String>,
qty: impl IntoQuantity,
stop_price: Decimal,
) -> SingleOrderBuilder<Ready>
pub fn sell_stop( symbol: impl Into<String>, qty: impl IntoQuantity, stop_price: Decimal, ) -> SingleOrderBuilder<Ready>
Equity stop-market sell, default day order. Useful for stop-loss exits.
Sourcepub fn sell_stop_limit(
symbol: impl Into<String>,
qty: impl IntoQuantity,
stop_price: Decimal,
limit_price: Decimal,
) -> SingleOrderBuilder<Ready>
pub fn sell_stop_limit( symbol: impl Into<String>, qty: impl IntoQuantity, stop_price: Decimal, limit_price: Decimal, ) -> SingleOrderBuilder<Ready>
Equity stop-limit sell, default day order. Triggered when the
market crosses stop_price, then becomes a limit order at
limit_price.
Sourcepub fn buy_to_open_market(
symbol: impl Into<String>,
qty: impl IntoQuantity,
) -> SingleOrderBuilder<Ready>
pub fn buy_to_open_market( symbol: impl Into<String>, qty: impl IntoQuantity, ) -> SingleOrderBuilder<Ready>
Option buy-to-open at market, default day order. Opens a long option position.
Sourcepub fn buy_to_open_limit(
symbol: impl Into<String>,
qty: impl IntoQuantity,
price: Decimal,
) -> SingleOrderBuilder<Ready>
pub fn buy_to_open_limit( symbol: impl Into<String>, qty: impl IntoQuantity, price: Decimal, ) -> SingleOrderBuilder<Ready>
Option buy-to-open at limit, default day order.
Sourcepub fn sell_to_open_market(
symbol: impl Into<String>,
qty: impl IntoQuantity,
) -> SingleOrderBuilder<Ready>
pub fn sell_to_open_market( symbol: impl Into<String>, qty: impl IntoQuantity, ) -> SingleOrderBuilder<Ready>
Option sell-to-open at market, default day order. Writes (shorts) an option.
Sourcepub fn sell_to_open_limit(
symbol: impl Into<String>,
qty: impl IntoQuantity,
price: Decimal,
) -> SingleOrderBuilder<Ready>
pub fn sell_to_open_limit( symbol: impl Into<String>, qty: impl IntoQuantity, price: Decimal, ) -> SingleOrderBuilder<Ready>
Option sell-to-open at limit, default day order.
Sourcepub fn buy_to_close_market(
symbol: impl Into<String>,
qty: impl IntoQuantity,
) -> SingleOrderBuilder<Ready>
pub fn buy_to_close_market( symbol: impl Into<String>, qty: impl IntoQuantity, ) -> SingleOrderBuilder<Ready>
Option buy-to-close at market, default day order. Closes a previously written (short) option.
Sourcepub fn buy_to_close_limit(
symbol: impl Into<String>,
qty: impl IntoQuantity,
price: Decimal,
) -> SingleOrderBuilder<Ready>
pub fn buy_to_close_limit( symbol: impl Into<String>, qty: impl IntoQuantity, price: Decimal, ) -> SingleOrderBuilder<Ready>
Option buy-to-close at limit, default day order.
Sourcepub fn sell_to_close_market(
symbol: impl Into<String>,
qty: impl IntoQuantity,
) -> SingleOrderBuilder<Ready>
pub fn sell_to_close_market( symbol: impl Into<String>, qty: impl IntoQuantity, ) -> SingleOrderBuilder<Ready>
Option sell-to-close at market, default day order. Closes a long option position.
Sourcepub fn sell_to_close_limit(
symbol: impl Into<String>,
qty: impl IntoQuantity,
price: Decimal,
) -> SingleOrderBuilder<Ready>
pub fn sell_to_close_limit( symbol: impl Into<String>, qty: impl IntoQuantity, price: Decimal, ) -> SingleOrderBuilder<Ready>
Option sell-to-close at limit, default day order.
Sourcepub fn oco(
child_a: impl Into<OrderRequest>,
child_b: impl Into<OrderRequest>,
) -> OrderRequest
pub fn oco( child_a: impl Into<OrderRequest>, child_b: impl Into<OrderRequest>, ) -> OrderRequest
One-cancels-other: two child orders, the first to fill cancels the
other. Top-level carries only orderStrategyType=OCO and the two
children; each child is a complete order in its own right
(typically a SINGLE).
Accepts either a finished OrderRequest or any
SingleOrderBuilder<Ready>; the shortcuts and the explicit
builder both satisfy impl Into<OrderRequest>.
The duration on each child controls how long that side stays
live - for a take-profit + stop-loss pair you typically want both
children set to Duration::GoodTillCancel via the builder.
§Examples
A bracket exit: a take-profit limit paired with a stop-loss, first to fill cancels the other. Both children are good-till-cancel so neither expires at the close.
use rust_decimal_macros::dec;
use schwab_sdk::orders::{Duration, OrderRequest};
let take_profit = OrderRequest::single()
.limit(dec!(15.27))
.equity_sell("XYZ", dec!(5))
.duration(Duration::GoodTillCancel)
.build();
let stop_loss = OrderRequest::single()
.stop(dec!(11.27))
.equity_sell("XYZ", dec!(5))
.duration(Duration::GoodTillCancel)
.build();
let bracket = OrderRequest::oco(take_profit, stop_loss);Sourcepub fn trigger(
parent: impl Into<OrderRequest>,
child: impl Into<OrderRequest>,
) -> OrderRequest
pub fn trigger( parent: impl Into<OrderRequest>, child: impl Into<OrderRequest>, ) -> OrderRequest
First-trigger-sequence: parent is the order Schwab places
immediately; once it fills, child is released. The parent’s
orderStrategyType is overwritten with TRIGGER.
Both arguments accept any impl Into<OrderRequest> - the
shortcuts return a SingleOrderBuilder<Ready> which is
converted transparently.
1st-Trigger-OCO is the composition
OrderRequest::trigger(parent, OrderRequest::oco(profit, stop)).
§Examples
Open a position, then attach a profit target and a stop once the entry fills (1st-trigger-OCO):
use rust_decimal_macros::dec;
use schwab_sdk::orders::{Duration, OrderRequest};
let entry = OrderRequest::buy_limit("XYZ", dec!(5), dec!(14.97));
let take_profit = OrderRequest::single()
.limit(dec!(15.27))
.equity_sell("XYZ", dec!(5))
.duration(Duration::GoodTillCancel)
.build();
let stop_loss = OrderRequest::single()
.stop(dec!(11.27))
.equity_sell("XYZ", dec!(5))
.duration(Duration::GoodTillCancel)
.build();
let order = OrderRequest::trigger(entry, OrderRequest::oco(take_profit, stop_loss));Trait Implementations§
Source§impl Clone for OrderRequest
impl Clone for OrderRequest
Source§fn clone(&self) -> OrderRequest
fn clone(&self) -> OrderRequest
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for OrderRequest
impl Debug for OrderRequest
Source§impl From<SingleOrderBuilder<Ready>> for OrderRequest
impl From<SingleOrderBuilder<Ready>> for OrderRequest
Source§fn from(builder: SingleOrderBuilder<Ready>) -> Self
fn from(builder: SingleOrderBuilder<Ready>) -> Self
Source§impl Hash for OrderRequest
impl Hash for OrderRequest
Source§impl PartialEq for OrderRequest
impl PartialEq for OrderRequest
Source§fn eq(&self, other: &OrderRequest) -> bool
fn eq(&self, other: &OrderRequest) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for OrderRequest
impl Serialize for OrderRequest
Source§impl TryFrom<Order> for OrderRequest
impl TryFrom<Order> for OrderRequest
Source§fn try_from(order: Order) -> Result<Self, Self::Error>
fn try_from(order: Order) -> Result<Self, Self::Error>
Convert a fetched Order into an OrderRequest body. Useful for
constructing the body of a replace request from a previously-fetched
order: take the live order, mutate the field(s) you want to change,
and send it back.
Broker-assigned fields (orderId, status, enteredTime,
cancelable, editable, fills, lineage, etc.) are not part of a
request body and are dropped. Child strategies (OCO / TRIGGER)
are converted recursively. Fields that cannot be represented in a
request (a leg missing its instrument, an instrument missing its
symbol) surface as Error::OrderResponseNotRepresentable.
impl Eq for OrderRequest
impl StructuralPartialEq for OrderRequest
Auto Trait Implementations§
impl Freeze for OrderRequest
impl RefUnwindSafe for OrderRequest
impl Send for OrderRequest
impl Sync for OrderRequest
impl Unpin for OrderRequest
impl UnsafeUnpin for OrderRequest
impl UnwindSafe for OrderRequest
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.