#[non_exhaustive]pub enum OrderSpec {
Market {
leg: LegSpec,
settings: OrderSettings,
},
Limit {
leg: LegSpec,
price: Decimal,
settings: OrderSettings,
},
Stop {
leg: LegSpec,
stop_price: Decimal,
settings: OrderSettings,
},
StopLimit {
leg: LegSpec,
stop_price: Decimal,
price: Decimal,
settings: OrderSettings,
},
TrailingStop {
leg: LegSpec,
basis: PriceLinkBasis,
link: PriceLinkType,
offset: Decimal,
settings: OrderSettings,
},
NetDebit {
legs: Vec<LegSpec>,
price: Decimal,
settings: OrderSettings,
},
NetCredit {
legs: Vec<LegSpec>,
price: Decimal,
settings: OrderSettings,
},
NetZero {
legs: Vec<LegSpec>,
settings: OrderSettings,
},
Oco {
first: Box<OrderSpec>,
second: Box<OrderSpec>,
},
Trigger {
entry: Box<OrderSpec>,
children: Vec<OrderSpec>,
},
Bracket {
entry: Box<OrderSpec>,
take_profit: Decimal,
stop_loss: Decimal,
},
}Expand description
One order, keyed by kind. Single orders take a leg (or legs for
the net-priced multi-leg kinds) and optional settings; oco,
trigger and bracket nest other specs.
use rustyschwab_types::trading::{OrderSpec, OrderStrategyType};
let spec: OrderSpec = serde_json::from_value(serde_json::json!({
"kind": "bracket",
"entry": {
"kind": "limit",
"leg": {"instruction": "BUY", "quantity": "10",
"instrument": {"asset_type": "EQUITY", "symbol": "AAPL"}},
"price": "150.25",
"settings": {"tag": "swing-1"}
},
"take_profit": "160",
"stop_loss": "145"
}))
.unwrap();
let order = spec.build().unwrap();
assert_eq!(order.order_strategy_type, OrderStrategyType::Trigger);
assert_eq!(order.child_order_strategies[0].child_order_strategies.len(), 2);Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Market
Fill at the market.
Limit
Fill at price or better.
Stop
Become a market order once stop_price trades.
StopLimit
Become a limit order at price once stop_price trades.
TrailingStop
A stop that trails basis by offset, expressed as link.
NetDebit
Multi-leg order paying at most price net.
NetCredit
Multi-leg order collecting at least price net.
NetZero
Multi-leg order that must fill for zero net cost.
Oco
Two orders; a fill on either cancels the other.
Trigger
children are submitted once entry fills.
Bracket
entry triggers a good-till-cancel take-profit limit and stop-loss
pair that close the entry leg; see OrderRequest::bracket.
Implementations§
Source§impl OrderSpec
impl OrderSpec
Sourcepub fn build(self) -> Result<OrderRequest, String>
pub fn build(self) -> Result<OrderRequest, String>
Expand into a validated OrderRequest.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for OrderSpec
impl<'de> Deserialize<'de> for OrderSpec
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>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for OrderSpec
Source§impl JsonSchema for OrderSpec
Available on crate feature schemars only.
impl JsonSchema for OrderSpec
Available on crate feature
schemars only.Source§fn schema_id() -> Cow<'static, str>
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
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn inline_schema() -> bool
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 moreimpl StructuralPartialEq for OrderSpec
Auto Trait Implementations§
impl Freeze for OrderSpec
impl RefUnwindSafe for OrderSpec
impl Send for OrderSpec
impl Sync for OrderSpec
impl Unpin for OrderSpec
impl UnsafeUnpin for OrderSpec
impl UnwindSafe for OrderSpec
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
Mutably borrows from an owned value. Read more