OrderBuilder

Struct OrderBuilder 

Source
pub struct OrderBuilder<'a, C> { /* private fields */ }
Expand description

Builder for creating orders with a fluent interface

All validation is deferred to the build() method to ensure no silent failures occur during order construction.

Implementations§

Source§

impl<'a, C> OrderBuilder<'a, C>

Source

pub fn new(client: &'a C, contract: &'a Contract) -> Self

Creates a new OrderBuilder

Source

pub fn buy(self, quantity: impl Into<f64>) -> Self

Set order to buy the specified quantity

Source

pub fn sell(self, quantity: impl Into<f64>) -> Self

Set order to sell the specified quantity

Source

pub fn market(self) -> Self

Create a market order

Source

pub fn limit(self, price: impl Into<f64>) -> Self

Create a limit order at the specified price

Source

pub fn stop(self, stop_price: impl Into<f64>) -> Self

Create a stop order at the specified stop price

Source

pub fn stop_limit( self, stop_price: impl Into<f64>, limit_price: impl Into<f64>, ) -> Self

Create a stop-limit order

Source

pub fn trailing_stop( self, trailing_percent: f64, stop_price: impl Into<f64>, ) -> Self

Create a trailing stop order

Source

pub fn order_type(self, order_type: OrderType) -> Self

Set a custom order type

Source

pub fn trailing_stop_limit( self, trailing_percent: f64, stop_price: impl Into<f64>, limit_offset: f64, ) -> Self

Create a trailing stop limit order

Source

pub fn market_if_touched(self, trigger_price: impl Into<f64>) -> Self

Market if Touched - triggers market order when price is touched

Source

pub fn limit_if_touched( self, trigger_price: impl Into<f64>, limit_price: impl Into<f64>, ) -> Self

Limit if Touched - triggers limit order when price is touched

Source

pub fn market_to_limit(self) -> Self

Market to Limit - starts as market order, remainder becomes limit

Source

pub fn discretionary( self, limit_price: impl Into<f64>, discretionary_amt: f64, ) -> Self

Discretionary order - limit order with hidden discretionary amount

Source

pub fn sweep_to_fill(self, limit_price: impl Into<f64>) -> Self

Sweep to Fill - prioritizes speed of execution over price

Source

pub fn block(self, limit_price: impl Into<f64>) -> Self

Block order - for large volume option orders (min 50 contracts)

Source

pub fn midprice(self, price_cap: impl Into<f64>) -> Self

Midprice order - fills at midpoint between bid/ask or better

Source

pub fn relative(self, offset: f64, price_cap: Option<f64>) -> Self

Relative/Pegged-to-Primary - seeks more aggressive price than NBBO

Source

pub fn passive_relative(self, offset: f64) -> Self

Passive Relative - seeks less aggressive price than NBBO

Source

pub fn at_auction(self, price: impl Into<f64>) -> Self

At Auction - for pre-market opening period execution

Source

pub fn time_in_force(self, tif: TimeInForce) -> Self

Set time in force for the order

Source

pub fn day_order(self) -> Self

Order valid for the day only

Source

pub fn good_till_cancel(self) -> Self

Good till cancelled order

Source

pub fn good_till_date(self, date: impl Into<String>) -> Self

Good till specific date

Source

pub fn fill_or_kill(self) -> Self

Fill or kill order

Source

pub fn immediate_or_cancel(self) -> Self

Immediate or cancel order

Source

pub fn outside_rth(self) -> Self

Allow order execution outside regular trading hours

Source

pub fn regular_hours_only(self) -> Self

Restrict order to regular trading hours only

Source

pub fn trading_hours(self, hours: TradingHours) -> Self

Set trading hours preference

Source

pub fn hidden(self) -> Self

Hide order from market depth (only works for NASDAQ-routed orders)

Source

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

Set account for order

Source

pub fn parent(self, parent_id: i32) -> Self

Set parent order ID for attached orders

Source

pub fn oca_group(self, group: impl Into<String>, oca_type: i32) -> Self

Set OCA group

Source

pub fn do_not_transmit(self) -> Self

Do not transmit order immediately

Source

pub fn bracket(self) -> BracketOrderBuilder<'a, C>

Create bracket orders with take profit and stop loss

Source

pub fn algo(self, strategy: impl Into<String>) -> Self

Set algorithm strategy

Source

pub fn algo_param( self, key: impl Into<String>, value: impl Into<String>, ) -> Self

Add algorithm parameter

Source

pub fn what_if(self) -> Self

Mark as what-if order for margin/commission calculation

Source

pub fn volatility(self, volatility: f64) -> Self

Set volatility for volatility orders

Source

pub fn not_held(self) -> Self

Mark order as not held

Source

pub fn all_or_none(self) -> Self

Mark order as all or none

Source

pub fn good_after_time(self, time: impl Into<String>) -> Self

Set good after time

Source

pub fn good_till_time(self, time: impl Into<String>) -> Self

Set good till time (stored in good_till_date field)

Source

pub fn min_trade_qty(self, qty: i32) -> Self

Set minimum trade quantity for pegged orders

Source

pub fn min_compete_size(self, size: i32) -> Self

Set minimum compete size for pegged orders

Source

pub fn compete_against_best_offset(self, offset: f64) -> Self

Set compete against best offset for pegged orders

Source

pub fn mid_offset_at_whole(self, offset: f64) -> Self

Set mid offset at whole for pegged orders

Source

pub fn mid_offset_at_half(self, offset: f64) -> Self

Set mid offset at half for pegged orders

Source

pub fn build(self) -> Result<Order, ValidationError>

Build the Order struct with full validation

Source§

impl<'a> OrderBuilder<'a, Client>

Source

pub fn submit(self) -> Result<OrderId, Error>

Submit the order synchronously Returns the order ID assigned to the submitted order

Source

pub fn build_order(self) -> Result<Order, Error>

Build the order and return it without submitting Useful for batch operations or custom submission logic

Source

pub fn analyze(self) -> Result<OrderState, Error>

Analyze order for margin/commission (what-if)

Source§

impl<'a> OrderBuilder<'a, Client>

Source

pub async fn submit(self) -> Result<OrderId, Error>

Submit the order asynchronously Returns the order ID assigned to the submitted order

Source

pub fn build_order(self) -> Result<Order, Error>

Build the order and return it without submitting Useful for batch operations or custom submission logic

Source

pub async fn analyze(self) -> Result<OrderState, Error>

Analyze order for margin/commission (what-if)

Auto Trait Implementations§

§

impl<'a, C> Freeze for OrderBuilder<'a, C>

§

impl<'a, C> RefUnwindSafe for OrderBuilder<'a, C>
where C: RefUnwindSafe,

§

impl<'a, C> Send for OrderBuilder<'a, C>
where C: Sync,

§

impl<'a, C> Sync for OrderBuilder<'a, C>
where C: Sync,

§

impl<'a, C> Unpin for OrderBuilder<'a, C>

§

impl<'a, C> UnwindSafe for OrderBuilder<'a, C>
where C: RefUnwindSafe,

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> 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.