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>
impl<'a, C> OrderBuilder<'a, C>
Sourcepub fn stop(self, stop_price: impl Into<f64>) -> Self
pub fn stop(self, stop_price: impl Into<f64>) -> Self
Create a stop order at the specified stop price
Sourcepub fn stop_limit(
self,
stop_price: impl Into<f64>,
limit_price: impl Into<f64>,
) -> Self
pub fn stop_limit( self, stop_price: impl Into<f64>, limit_price: impl Into<f64>, ) -> Self
Create a stop-limit order
Sourcepub fn trailing_stop(
self,
trailing_percent: f64,
stop_price: impl Into<f64>,
) -> Self
pub fn trailing_stop( self, trailing_percent: f64, stop_price: impl Into<f64>, ) -> Self
Create a trailing stop order
Sourcepub fn order_type(self, order_type: OrderType) -> Self
pub fn order_type(self, order_type: OrderType) -> Self
Set a custom order type
Sourcepub fn trailing_stop_limit(
self,
trailing_percent: f64,
stop_price: impl Into<f64>,
limit_offset: f64,
) -> Self
pub fn trailing_stop_limit( self, trailing_percent: f64, stop_price: impl Into<f64>, limit_offset: f64, ) -> Self
Create a trailing stop limit order
Sourcepub fn market_if_touched(self, trigger_price: impl Into<f64>) -> Self
pub fn market_if_touched(self, trigger_price: impl Into<f64>) -> Self
Market if Touched - triggers market order when price is touched
Sourcepub fn limit_if_touched(
self,
trigger_price: impl Into<f64>,
limit_price: impl Into<f64>,
) -> Self
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
Sourcepub fn market_to_limit(self) -> Self
pub fn market_to_limit(self) -> Self
Market to Limit - starts as market order, remainder becomes limit
Sourcepub fn discretionary(
self,
limit_price: impl Into<f64>,
discretionary_amt: f64,
) -> Self
pub fn discretionary( self, limit_price: impl Into<f64>, discretionary_amt: f64, ) -> Self
Discretionary order - limit order with hidden discretionary amount
Sourcepub fn sweep_to_fill(self, limit_price: impl Into<f64>) -> Self
pub fn sweep_to_fill(self, limit_price: impl Into<f64>) -> Self
Sweep to Fill - prioritizes speed of execution over price
Sourcepub fn block(self, limit_price: impl Into<f64>) -> Self
pub fn block(self, limit_price: impl Into<f64>) -> Self
Block order - for large volume option orders (min 50 contracts)
Sourcepub fn midprice(self, price_cap: Option<f64>) -> Self
pub fn midprice(self, price_cap: Option<f64>) -> Self
Midprice order - fills at midpoint between bid/ask or better
Sourcepub fn relative(self, offset: f64, price_cap: Option<f64>) -> Self
pub fn relative(self, offset: f64, price_cap: Option<f64>) -> Self
Relative/Pegged-to-Primary - seeks more aggressive price than NBBO
Sourcepub fn passive_relative(self, offset: f64) -> Self
pub fn passive_relative(self, offset: f64) -> Self
Passive Relative - seeks less aggressive price than NBBO
Sourcepub fn at_auction(self, price: impl Into<f64>) -> Self
pub fn at_auction(self, price: impl Into<f64>) -> Self
At Auction - for pre-market opening period execution
Sourcepub fn market_on_close(self) -> Self
pub fn market_on_close(self) -> Self
Market on Close - executes as market order at or near closing price
Sourcepub fn limit_on_close(self, limit_price: impl Into<f64>) -> Self
pub fn limit_on_close(self, limit_price: impl Into<f64>) -> Self
Limit on Close - executes as limit order at close if price is met
Sourcepub fn market_on_open(self) -> Self
pub fn market_on_open(self) -> Self
Market on Open - executes as market order at market open
Sourcepub fn limit_on_open(self, limit_price: impl Into<f64>) -> Self
pub fn limit_on_open(self, limit_price: impl Into<f64>) -> Self
Limit on Open - executes as limit order at market open
Sourcepub fn market_with_protection(self) -> Self
pub fn market_with_protection(self) -> Self
Market with Protection - market order with protection against extreme price movements (futures only)
Sourcepub fn stop_with_protection(self, stop_price: impl Into<f64>) -> Self
pub fn stop_with_protection(self, stop_price: impl Into<f64>) -> Self
Stop with Protection - stop order with protection against extreme price movements (futures only)
Sourcepub fn time_in_force(self, tif: TimeInForce) -> Self
pub fn time_in_force(self, tif: TimeInForce) -> Self
Set time in force for the order
Sourcepub fn good_till_cancel(self) -> Self
pub fn good_till_cancel(self) -> Self
Good till cancelled order
Sourcepub fn good_till_date(self, date: impl Into<String>) -> Self
pub fn good_till_date(self, date: impl Into<String>) -> Self
Good till specific date
Sourcepub fn fill_or_kill(self) -> Self
pub fn fill_or_kill(self) -> Self
Fill or kill order
Sourcepub fn immediate_or_cancel(self) -> Self
pub fn immediate_or_cancel(self) -> Self
Immediate or cancel order
Sourcepub fn outside_rth(self) -> Self
pub fn outside_rth(self) -> Self
Allow order execution outside regular trading hours
Sourcepub fn regular_hours_only(self) -> Self
pub fn regular_hours_only(self) -> Self
Restrict order to regular trading hours only
Sourcepub fn trading_hours(self, hours: TradingHours) -> Self
pub fn trading_hours(self, hours: TradingHours) -> Self
Set trading hours preference
Hide order from market depth (only works for NASDAQ-routed orders)
Sourcepub fn do_not_transmit(self) -> Self
pub fn do_not_transmit(self) -> Self
Do not transmit order immediately
Sourcepub fn bracket(self) -> BracketOrderBuilder<'a, C>
pub fn bracket(self) -> BracketOrderBuilder<'a, C>
Create bracket orders with take profit and stop loss
Sourcepub fn condition(self, condition: impl Into<OrderCondition>) -> Self
pub fn condition(self, condition: impl Into<OrderCondition>) -> Self
Add a condition to the order.
The first condition is always treated as AND. Use and_condition() or or_condition()
for subsequent conditions to specify the logical relationship.
§Example
use ibapi::orders::builder::price;
let order_id = client.order(&contract)
.buy(100)
.market()
.condition(price(265598, "SMART").greater_than(150.0))
.submit().await?;Sourcepub fn and_condition(self, condition: impl Into<OrderCondition>) -> Self
pub fn and_condition(self, condition: impl Into<OrderCondition>) -> Self
Add a condition that must be met along with previous conditions (AND logic).
§Example
use ibapi::orders::builder::{price, margin};
let order_id = client.order(&contract)
.buy(100)
.market()
.condition(price(265598, "SMART").greater_than(150.0))
.and_condition(margin().greater_than(30))
.submit().await?;Sourcepub fn or_condition(self, condition: impl Into<OrderCondition>) -> Self
pub fn or_condition(self, condition: impl Into<OrderCondition>) -> Self
Add a condition where either this OR previous conditions trigger the order (OR logic).
§Example
use ibapi::orders::builder::{price, volume};
let order_id = client.order(&contract)
.buy(100)
.market()
.condition(price(265598, "SMART").less_than(100.0))
.or_condition(volume(265598, "SMART").greater_than(50_000_000))
.submit().await?;Sourcepub fn algo(self, algo: impl Into<AlgoParams>) -> Self
pub fn algo(self, algo: impl Into<AlgoParams>) -> Self
Set algorithm strategy and parameters.
Accepts either a strategy name (string) or an algo builder.
§Example with builder
use ibapi::orders::builder::vwap;
let order_id = client.order(&contract)
.buy(1000)
.limit(150.0)
.algo(vwap()
.max_pct_vol(0.2)
.start_time("09:00:00 US/Eastern")
.end_time("16:00:00 US/Eastern")
.build()?)
.submit().await?;§Example with string (for custom strategies)
let order_id = client.order(&contract)
.buy(1000)
.limit(150.0)
.algo("Vwap")
.algo_param("maxPctVol", "0.2")
.submit().await?;Sourcepub fn algo_param(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn algo_param( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Add algorithm parameter.
Use this to add individual parameters when using a strategy name string. When using algo builders, parameters are set via the builder methods.
Sourcepub fn volatility(self, volatility: f64) -> Self
pub fn volatility(self, volatility: f64) -> Self
Set volatility for volatility orders
Sourcepub fn all_or_none(self) -> Self
pub fn all_or_none(self) -> Self
Mark order as all or none
Sourcepub fn good_after_time(self, time: impl Into<String>) -> Self
pub fn good_after_time(self, time: impl Into<String>) -> Self
Set good after time
Sourcepub fn good_till_time(self, time: impl Into<String>) -> Self
pub fn good_till_time(self, time: impl Into<String>) -> Self
Set good till time (stored in good_till_date field)
Sourcepub fn min_trade_qty(self, qty: i32) -> Self
pub fn min_trade_qty(self, qty: i32) -> Self
Set minimum trade quantity for pegged orders
Sourcepub fn min_compete_size(self, size: i32) -> Self
pub fn min_compete_size(self, size: i32) -> Self
Set minimum compete size for pegged orders
Sourcepub fn compete_against_best_offset(self, offset: f64) -> Self
pub fn compete_against_best_offset(self, offset: f64) -> Self
Set compete against best offset for pegged orders
Sourcepub fn mid_offset_at_whole(self, offset: f64) -> Self
pub fn mid_offset_at_whole(self, offset: f64) -> Self
Set mid offset at whole for pegged orders
Sourcepub fn mid_offset_at_half(self, offset: f64) -> Self
pub fn mid_offset_at_half(self, offset: f64) -> Self
Set mid offset at half for pegged orders
Sourcepub fn build(self) -> Result<Order, ValidationError>
pub fn build(self) -> Result<Order, ValidationError>
Build the Order struct with full validation
Source§impl<'a> OrderBuilder<'a, Client>
impl<'a> OrderBuilder<'a, Client>
Sourcepub fn submit(self) -> Result<OrderId, Error>
pub fn submit(self) -> Result<OrderId, Error>
Submit the order synchronously Returns the order ID assigned to the submitted order
Sourcepub fn build_order(self) -> Result<Order, Error>
pub fn build_order(self) -> Result<Order, Error>
Build the order and return it without submitting Useful for batch operations or custom submission logic
Sourcepub fn analyze(self) -> Result<OrderState, Error>
pub fn analyze(self) -> Result<OrderState, Error>
Analyze order for margin/commission (what-if)
Source§impl<'a> OrderBuilder<'a, Client>
impl<'a> OrderBuilder<'a, Client>
Sourcepub async fn submit(self) -> Result<OrderId, Error>
pub async fn submit(self) -> Result<OrderId, Error>
Submit the order asynchronously Returns the order ID assigned to the submitted order
Sourcepub fn build_order(self) -> Result<Order, Error>
pub fn build_order(self) -> Result<Order, Error>
Build the order and return it without submitting Useful for batch operations or custom submission logic
Sourcepub async fn analyze(self) -> Result<OrderState, Error>
pub async fn analyze(self) -> Result<OrderState, Error>
Analyze order for margin/commission (what-if)