Skip to main content

OrderRequest

Struct OrderRequest 

Source
#[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

Source

pub fn session(&self) -> Option<&Session>

Session in which the order is eligible to trade.

Source

pub fn duration(&self) -> Option<&Duration>

Time in force (DAY, GOOD_TILL_CANCEL, etc.).

Source

pub fn order_type(&self) -> Option<&OrderType>

Order type (MARKET, LIMIT, STOP, NET_DEBIT, etc.).

Source

pub fn complex_order_strategy_type(&self) -> Option<&ComplexOrderStrategyType>

Multi-leg option strategy shape, if any.

Source

pub fn quantity(&self) -> Option<Decimal>

Top-level quantity, when Schwab carries it separately from the per-leg quantity.

Source

pub fn price(&self) -> Option<Decimal>

Limit / net-debit / net-credit price.

Source

pub fn stop_price(&self) -> Option<Decimal>

Stop-trigger price for stop and stop-limit orders.

Source

pub fn special_instruction(&self) -> Option<&SpecialInstruction>

Special instruction (e.g. AllOrNone).

Source

pub fn order_strategy_type(&self) -> Option<&OrderStrategyType>

Envelope strategy (SINGLE, OCO, TRIGGER, …).

Source

pub fn legs(&self) -> &[OrderLegRequest]

Order legs.

Source

pub fn child_strategies(&self) -> &[OrderRequest]

Child strategies of a composite envelope (OCO or TRIGGER). Empty for SINGLE.

Source§

impl OrderRequest

Source

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.

Source

pub fn buy_market( symbol: impl Into<String>, qty: impl IntoQuantity, ) -> SingleOrderBuilder<Ready>

Equity buy-at-market, default day order.

Source

pub fn buy_limit( symbol: impl Into<String>, qty: impl IntoQuantity, price: Decimal, ) -> SingleOrderBuilder<Ready>

Equity buy-at-limit, default day order.

Source

pub fn sell_market( symbol: impl Into<String>, qty: impl IntoQuantity, ) -> SingleOrderBuilder<Ready>

Equity long-sale at market, default day order.

Source

pub fn sell_limit( symbol: impl Into<String>, qty: impl IntoQuantity, price: Decimal, ) -> SingleOrderBuilder<Ready>

Equity long-sale at limit, default day order.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

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

Source§

fn clone(&self) -> OrderRequest

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OrderRequest

Source§

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

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

impl From<SingleOrderBuilder<Ready>> for OrderRequest

Source§

fn from(builder: SingleOrderBuilder<Ready>) -> Self

Converts to this type from the input type.
Source§

impl Hash for OrderRequest

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for OrderRequest

Source§

fn eq(&self, other: &OrderRequest) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for OrderRequest

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<Order> for OrderRequest

Source§

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.

Source§

type Error = Error

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

impl Eq for OrderRequest

Source§

impl StructuralPartialEq for OrderRequest

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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, 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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