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
impl OrderRequest
pub fn market(leg: OrderRequestLeg) -> Self
pub fn limit(leg: OrderRequestLeg, price: Decimal) -> Self
Sourcepub fn stop(leg: OrderRequestLeg, stop_price: Decimal) -> Self
pub fn stop(leg: OrderRequestLeg, stop_price: Decimal) -> Self
A stop order that becomes a market order at stop_price.
Sourcepub fn stop_limit(
leg: OrderRequestLeg,
stop_price: Decimal,
price: Decimal,
) -> Self
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.
Sourcepub fn trailing_stop(
leg: OrderRequestLeg,
basis: PriceLinkBasis,
link: PriceLinkType,
offset: Decimal,
) -> Self
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.
Sourcepub fn net_debit(legs: Vec<OrderRequestLeg>, price: Decimal) -> Self
pub fn net_debit(legs: Vec<OrderRequestLeg>, price: Decimal) -> Self
A multi-leg order that pays at most price net.
Sourcepub fn net_credit(legs: Vec<OrderRequestLeg>, price: Decimal) -> Self
pub fn net_credit(legs: Vec<OrderRequestLeg>, price: Decimal) -> Self
A multi-leg order that collects at least price net.
Sourcepub fn net_zero(legs: Vec<OrderRequestLeg>) -> Self
pub fn net_zero(legs: Vec<OrderRequestLeg>) -> Self
A multi-leg order that must fill for zero net cost.
pub fn with_session(self, session: OrderSession) -> Self
pub fn with_duration(self, duration: OrderDuration) -> Self
pub fn with_tag(self, tag: impl Into<String>) -> Self
pub fn with_complex_strategy(self, strategy: ComplexOrderStrategyType) -> Self
pub fn with_special_instruction(self, instruction: SpecialInstruction) -> Self
pub fn with_destination(self, destination: RequestedDestination) -> Self
pub fn with_tax_lot_method(self, method: TaxLotMethod) -> Self
pub fn with_stop_type(self, stop_type: StopType) -> Self
Sourcepub fn one_cancels_other(first: OrderRequest, second: OrderRequest) -> Self
pub fn one_cancels_other(first: OrderRequest, second: OrderRequest) -> Self
Two orders of which a fill on either cancels the other.
Sourcepub fn triggers(self, child: OrderRequest) -> Self
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.
Sourcepub fn bracket(
self,
take_profit: Decimal,
stop_loss: Decimal,
) -> Result<Self, String>
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
impl OrderRequest
Sourcepub fn validate(&self) -> Result<(), ValidationError>
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.
Sourcepub fn validate_price_increment(
&self,
tick: Decimal,
) -> Result<(), ValidationError>
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
impl Clone for OrderRequest
Source§impl Debug for OrderRequest
impl Debug for OrderRequest
Source§impl Default for OrderRequest
impl Default for OrderRequest
Source§impl<'de> Deserialize<'de> for OrderRequest
impl<'de> Deserialize<'de> for OrderRequest
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl JsonSchema for OrderRequest
impl JsonSchema for OrderRequest
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl PartialEq for OrderRequest
impl PartialEq for OrderRequest
Source§impl Serialize for OrderRequest
impl Serialize for OrderRequest
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.
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.