Skip to main content

OrderRequest

Struct OrderRequest 

Source
pub struct OrderRequest {
Show 23 fields pub session: Option<OrderSession>, pub duration: Option<OrderDuration>, pub order_type: Option<OrderType>, pub complex_order_strategy_type: Option<ComplexOrderStrategyType>, pub quantity: Option<Decimal>, pub price: Option<Decimal>, pub stop_price: Option<Decimal>, pub stop_price_link_basis: Option<PriceLinkBasis>, pub stop_price_link_type: Option<PriceLinkType>, pub stop_price_offset: Option<Decimal>, pub stop_type: Option<StopType>, pub price_link_basis: Option<PriceLinkBasis>, pub price_link_type: Option<PriceLinkType>, pub tax_lot_method: Option<TaxLotMethod>, pub tag: Option<String>, pub special_instruction: Option<SpecialInstruction>, pub requested_destination: Option<RequestedDestination>, pub release_time: Option<DateTime<Utc>>, pub cancel_time: Option<DateTime<Utc>>, pub activation_price: Option<Decimal>, pub order_leg_collection: Vec<OrderRequestLeg>, pub order_strategy_type: OrderStrategyType, pub child_order_strategies: Vec<OrderRequest>,
}
Expand description

Outgoing orders have a strict schema, separate from tolerant broker responses. Unsupported fields fail deserialization rather than silently altering a trade, and decimals parse exactly (see exact_decimal).

Fields§

§session: Option<OrderSession>§duration: Option<OrderDuration>§order_type: Option<OrderType>§complex_order_strategy_type: Option<ComplexOrderStrategyType>§quantity: Option<Decimal>

The order’s unit count, when present: a single leg trades exactly it, and each leg of a multi-leg order a whole multiple of it (a 1x2 ratio of 5 has legs of 5 and 10). Sent as a JSON number.

§price: Option<Decimal>§stop_price: Option<Decimal>§stop_price_link_basis: Option<PriceLinkBasis>§stop_price_link_type: Option<PriceLinkType>§stop_price_offset: Option<Decimal>§stop_type: Option<StopType>§price_link_basis: Option<PriceLinkBasis>§price_link_type: Option<PriceLinkType>§tax_lot_method: Option<TaxLotMethod>§tag: Option<String>§special_instruction: Option<SpecialInstruction>§requested_destination: Option<RequestedDestination>§release_time: Option<DateTime<Utc>>

Hold the order until this time (Schwab reports it AWAITING_RELEASE_TIME until then).

§cancel_time: Option<DateTime<Utc>>

Cancel the order at this time if it has not filled.

§activation_price: Option<Decimal>

The price at which a conditional order activates.

§order_leg_collection: Vec<OrderRequestLeg>§order_strategy_type: OrderStrategyType§child_order_strategies: Vec<OrderRequest>

Implementations§

Source§

impl OrderRequest

Source

pub fn market(leg: OrderRequestLeg) -> Self

Source

pub fn limit(leg: OrderRequestLeg, price: Decimal) -> Self

Source

pub fn stop(leg: OrderRequestLeg, stop_price: Decimal) -> Self

A stop order that becomes a market order at stop_price.

Source

pub fn stop_limit( leg: OrderRequestLeg, stop_price: Decimal, price: Decimal, ) -> Self

A stop order that becomes a limit order at price once stop_price trades.

Source

pub fn trailing_stop( leg: OrderRequestLeg, basis: PriceLinkBasis, link: PriceLinkType, offset: Decimal, ) -> Self

A stop that trails basis by offset, expressed as link (a price difference, a percentage, or ticks).

There is no trailing_stop_limit constructor on purpose: Schwab’s schema has no priceOffset and no published TRAILING_STOP_LIMIT example, so how the limit should be linked is unspecified. To send one, set order_type to OrderType::TrailingStopLimit and a fixed price on the result (the reading validate() enforces) and confirm the shape with a preview first.

Source

pub fn net_debit(legs: Vec<OrderRequestLeg>, price: Decimal) -> Self

A multi-leg order that pays at most price net.

Source

pub fn net_credit(legs: Vec<OrderRequestLeg>, price: Decimal) -> Self

A multi-leg order that collects at least price net.

Source

pub fn net_zero(legs: Vec<OrderRequestLeg>) -> Self

A multi-leg order that must fill for zero net cost.

Source

pub fn with_session(self, session: OrderSession) -> Self

Source

pub fn with_duration(self, duration: OrderDuration) -> Self

Source

pub fn with_tag(self, tag: impl Into<String>) -> Self

Source

pub fn with_complex_strategy(self, strategy: ComplexOrderStrategyType) -> Self

Source

pub fn with_special_instruction(self, instruction: SpecialInstruction) -> Self

Source

pub fn with_destination(self, destination: RequestedDestination) -> Self

Source

pub fn with_tax_lot_method(self, method: TaxLotMethod) -> Self

Source

pub fn with_stop_type(self, stop_type: StopType) -> Self

Source

pub fn one_cancels_other(first: OrderRequest, second: OrderRequest) -> Self

Two orders of which a fill on either cancels the other.

Source

pub fn triggers(self, child: OrderRequest) -> Self

Make this order a TRIGGER parent: child is submitted only after this order fills. Call again to trigger several children.

Source

pub fn bracket( self, take_profit: Decimal, stop_loss: Decimal, ) -> Result<Self, String>

Attach a take-profit limit and a stop-loss to a single-leg opening order: the exits are a good-till-cancel OCO pair that Schwab submits once the entry fills, using the closing instruction and full quantity of the entry leg.

Fails if the entry is not a single-leg SINGLE order, if its instruction does not open a position, or if the exits are on the wrong sides for the position’s direction: of each other always, and of the entry’s price: its limit (LIMIT, STOP_LIMIT), or for a STOP entry its trigger. A long entry at 150 needs its stop below 150 and its target above; otherwise an exit is marketable the moment the entry fills. A market entry has no price to compare, so only the ordering of the exits is checked.

Source§

impl OrderRequest

Source

pub fn validate(&self) -> Result<(), ValidationError>

Validates structure without silently rounding prices: every field the order type takes and none it does not, instructions that fit the asset, whole shares and contracts, canonical symbols, extended hours only for limit orders. Broker eligibility, buying power and asset-specific increments still require a preview.

Source

pub fn validate_price_increment( &self, tick: Decimal, ) -> Result<(), ValidationError>

Enforce a caller-supplied broker/asset tick size on every price and on a trailing offset expressed as a value; never round implicitly.

Trait Implementations§

Source§

impl Clone for OrderRequest

Source§

fn clone(&self) -> Self

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 Default for OrderRequest

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for OrderRequest

Source§

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

Deserialize this value from the given Serde deserializer. Read more
Source§

impl JsonSchema for OrderRequest

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl PartialEq for OrderRequest

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
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 StructuralPartialEq for OrderRequest

Source§

impl TryFrom<&Order> for OrderRequest

The request that would place order again, to edit for a replacement: its strategy, legs, prices and timing, without what Schwab assigned (ID, status, fills) and without its tag, which belongs to the original intent. Fails when a reported number has no exact decimal spelling.

Source§

type Error = ValidationError

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

fn try_from(order: &Order) -> Result<Self, ValidationError>

Performs the conversion.
Source§

impl TryFrom<OrderSpec> for OrderRequest

Source§

type Error = String

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

fn try_from(spec: OrderSpec) -> Result<Self, Self::Error>

Performs the conversion.

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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.