Skip to main content

OrderSpec

Enum OrderSpec 

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

Fields

§settings: OrderSettings
§

Limit

Fill at price or better.

Fields

§price: Decimal
§settings: OrderSettings
§

Stop

Become a market order once stop_price trades.

Fields

§stop_price: Decimal
§settings: OrderSettings
§

StopLimit

Become a limit order at price once stop_price trades.

Fields

§stop_price: Decimal
§price: Decimal
§settings: OrderSettings
§

TrailingStop

A stop that trails basis by offset, expressed as link.

§

NetDebit

Multi-leg order paying at most price net.

Fields

§legs: Vec<LegSpec>
§price: Decimal
§settings: OrderSettings
§

NetCredit

Multi-leg order collecting at least price net.

Fields

§legs: Vec<LegSpec>
§price: Decimal
§settings: OrderSettings
§

NetZero

Multi-leg order that must fill for zero net cost.

Fields

§legs: Vec<LegSpec>
§settings: OrderSettings
§

Oco

Two orders; a fill on either cancels the other.

Fields

§second: Box<OrderSpec>
§

Trigger

children are submitted once entry fills.

Fields

§children: Vec<OrderSpec>
§

Bracket

entry triggers a good-till-cancel take-profit limit and stop-loss pair that close the entry leg; see OrderRequest::bracket.

Fields

§take_profit: Decimal
§stop_loss: Decimal

Implementations§

Source§

impl OrderSpec

Source

pub fn build(self) -> Result<OrderRequest, String>

Expand into a validated OrderRequest.

Trait Implementations§

Source§

impl Clone for OrderSpec

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 OrderSpec

Source§

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

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

impl<'de> Deserialize<'de> for OrderSpec

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 Eq for OrderSpec

Source§

impl JsonSchema for OrderSpec

Available on crate feature schemars only.
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 OrderSpec

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 OrderSpec

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 OrderSpec

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.