Struct ConditionalBuilder
pub struct ConditionalBuilder { /* private fields */ }Expand description
Builder for constructing Conditional orders with a fluent API.
This builder provides a type-safe way to construct conditional orders with proper validation of required fields and configuration constraints. It supports:
- Price-based triggers (rises above/falls below)
- Order-linked activation (bracket orders)
- Flexible quantity specifications
- Optional expiry configuration
It will also build a trailing-stop trigger or an OCO link, but the sequencer
rejects both (125 and 129) — see Trigger and Conditional.
§Required Fields
The following fields must be set before calling build():
- Trigger condition:
rises_above()orfalls_below() - Trigger: Price level or trailing configuration
- Reference price:
last_trade_price(),index_price(), ormark_price()
§Examples
Basic stop-loss order:
use types::api::submit_order::{ConditionalBuilder, Trigger};
let conditional = ConditionalBuilder::new()
.falls_below()
.trigger(Trigger::price("45000.00"))
.last_trade_price()
.build()
.unwrap();Stop with order-linked activation:
use types::api::submit_order::{ConditionalBuilder, Trigger};
let conditional = ConditionalBuilder::new()
.falls_below()
.trigger(Trigger::price("45000.00"))
.mark_price()
.order_linked_activation_client_id("entry-order-123", "1.0")
.absolute_quantity("1.0")
.build()
.unwrap();Take-profit on half the position:
use types::api::submit_order::{ConditionalBuilder, Trigger};
let take_profit = ConditionalBuilder::new()
.rises_above()
.trigger(Trigger::price("55000.00"))
.last_trade_price()
.percentage_of_position_at_trigger("0.5")
.build()
.unwrap();Implementations§
§impl ConditionalBuilder
impl ConditionalBuilder
pub fn new() -> ConditionalBuilder
pub fn new() -> ConditionalBuilder
Creates a new ConditionalBuilder with all fields unset.
§Example
use types::api::submit_order::ConditionalBuilder;
let builder = ConditionalBuilder::new();pub fn trigger_condition(
self,
condition: TriggerCondition,
) -> ConditionalBuilder
pub fn trigger_condition( self, condition: TriggerCondition, ) -> ConditionalBuilder
Sets the trigger condition directly.
Tip: Consider using rises_above() or
falls_below() for better readability.
§Arguments
condition- The trigger condition to use
§Example
use types::api::submit_order::ConditionalBuilder;
use types::common::TriggerCondition;
let builder = ConditionalBuilder::new()
.trigger_condition(TriggerCondition::RisesAbove);pub fn rises_above(self) -> ConditionalBuilder
pub fn rises_above(self) -> ConditionalBuilder
Sets trigger condition to RisesAbove (for breakout/take-profit orders).
The order will trigger when the reference price rises above the trigger level.
Required field - Must be set before calling build().
§Example
use types::api::submit_order::ConditionalBuilder;
let builder = ConditionalBuilder::new()
.rises_above(); // Trigger when price rises above targetpub fn falls_below(self) -> ConditionalBuilder
pub fn falls_below(self) -> ConditionalBuilder
Sets trigger condition to FallsBelow (for stop-loss orders).
The order will trigger when the reference price falls below the trigger level.
Required field - Must be set before calling build().
§Example
use types::api::submit_order::ConditionalBuilder;
let builder = ConditionalBuilder::new()
.falls_below(); // Trigger when price falls below stop levelpub fn trigger(self, trigger: Trigger) -> ConditionalBuilder
pub fn trigger(self, trigger: Trigger) -> ConditionalBuilder
Sets the trigger mechanism (price or trailing stop).
Required field - Must be set before calling build().
§Arguments
trigger- Either a fixed price level or trailing stop configuration
§Example
use types::api::submit_order::{ConditionalBuilder, Trigger};
// Fixed price trigger
let builder = ConditionalBuilder::new()
.trigger(Trigger::price("50000.00"));
// Trailing stop trigger
let builder = ConditionalBuilder::new()
.trigger(Trigger::numeric_trailing_distance("500.00"));pub fn reference_price(
self,
reference_price: ReferencePrice,
) -> ConditionalBuilder
pub fn reference_price( self, reference_price: ReferencePrice, ) -> ConditionalBuilder
Sets the reference price source directly.
Tip: Consider using last_trade_price(),
index_price(), or mark_price()
for better readability.
Required field - Must be set before calling build().
pub fn last_trade_price(self) -> ConditionalBuilder
pub fn last_trade_price(self) -> ConditionalBuilder
pub fn index_price(self) -> ConditionalBuilder
pub fn index_price(self) -> ConditionalBuilder
pub fn mark_price(self) -> ConditionalBuilder
pub fn mark_price(self) -> ConditionalBuilder
pub fn expiry(self, expiry: ConditionalExpiry) -> ConditionalBuilder
pub fn expiry(self, expiry: ConditionalExpiry) -> ConditionalBuilder
Sets an optional expiry configuration.
When the expiry timestamp is reached, the conditional order will either trigger or cancel based on the expiry settings.
§Arguments
expiry- Expiry configuration with timestamp and action
§Example
use types::api::submit_order::{ConditionalBuilder, ConditionalExpiry};
let builder = ConditionalBuilder::new()
.expiry(ConditionalExpiry::trigger_at(1747313713));pub fn quantity(self, quantity: Quantity) -> ConditionalBuilder
pub fn quantity(self, quantity: Quantity) -> ConditionalBuilder
Sets the order quantity directly.
Tip: Consider using specific methods like absolute_quantity()
or percentage_of_position_at_trigger().
pub fn absolute_quantity<S>(self, quantity: S) -> ConditionalBuilder
pub fn absolute_quantity<S>(self, quantity: S) -> ConditionalBuilder
pub fn percentage_of_position_at_trigger<S>(
self,
percentage: S,
) -> ConditionalBuilder
pub fn percentage_of_position_at_trigger<S>( self, percentage: S, ) -> ConditionalBuilder
Sets quantity as a percentage of position at trigger time.
The quantity will be calculated based on the position size when the conditional order triggers (not when it’s submitted).
§Arguments
percentage- a fraction of the position in(0,1], as a decimal string ("0.5"is 50%). Anything zero, negative or greater than 1 is rejected withOrderPercentageOfPositionQuantityMustBeGreaterThanZeroAndLesserThanOne(139).
§Example
use types::api::submit_order::ConditionalBuilder;
let builder = ConditionalBuilder::new()
.percentage_of_position_at_trigger("0.5"); // 50% of positionpub fn percentage_of_position_at_submission<S>(
self,
percentage: S,
) -> ConditionalBuilder
pub fn percentage_of_position_at_submission<S>( self, percentage: S, ) -> ConditionalBuilder
Sets quantity as a percentage of position at submission time.
The quantity will be calculated and locked based on the position size when the conditional order is submitted (not when it triggers).
§Arguments
percentage- Percentage as a decimal string (e.g., “50” for 50%)
§Example
use types::api::submit_order::ConditionalBuilder;
let builder = ConditionalBuilder::new()
.percentage_of_position_at_submission("0.5"); // 50% of current positionpub fn order_link_quantity(self) -> ConditionalBuilder
pub fn order_link_quantity(self) -> ConditionalBuilder
Sets quantity to match the linked order’s full quantity.
Not supported. The sequencer rejects any conditional carrying this
quantity with OrderLinkQuantityNotSupported (133), whether or not order
linking is configured. Use absolute_quantity()
or a percentage-of-position quantity.
Requires: Order linking must be configured via
order_linked_activation_client_id() or
order_linked_activation_order_id().
§Example
use types::api::submit_order::ConditionalBuilder;
let builder = ConditionalBuilder::new()
.order_linked_activation_client_id("entry-order-123", "1.0")
.order_link_quantity(); // Match the linked order's quantitypub fn filled_order_link_quantity(self) -> ConditionalBuilder
pub fn filled_order_link_quantity(self) -> ConditionalBuilder
Sets quantity to match the linked order’s filled quantity.
Not supported. The sequencer rejects any conditional carrying this
quantity with OrderLinkQuantityNotSupported (133).
Requires: Order linking must be configured via
order_linked_activation_client_id() or
order_linked_activation_order_id().
§Example
use types::api::submit_order::ConditionalBuilder;
let builder = ConditionalBuilder::new()
.order_linked_activation_client_id("entry-order-123", "1.0")
.filled_order_link_quantity(); // Match filled portion onlypub fn order_linked_activation_client_id<S>(
self,
client_order_id: S,
fill_quantity: S,
) -> ConditionalBuilder
pub fn order_linked_activation_client_id<S>( self, client_order_id: S, fill_quantity: S, ) -> ConditionalBuilder
Links this conditional order to activate when another order is filled.
This creates a bracket order relationship where this conditional order activates after the specified parent order reaches a fill threshold.
Note: Cannot be used with order_linked_activation_order_id().
§Arguments
client_order_id- Client-assigned ID of the parent orderfill_quantity- Minimum fill quantity to activate (decimal string)
§Example
use types::api::submit_order::ConditionalBuilder;
let builder = ConditionalBuilder::new()
.order_linked_activation_client_id("entry-order-123", "1.0");pub fn order_linked_activation_order_id<S>(
self,
order_id: u128,
fill_quantity: S,
) -> ConditionalBuilder
pub fn order_linked_activation_order_id<S>( self, order_id: u128, fill_quantity: S, ) -> ConditionalBuilder
Links this conditional order to activate when another order is filled (by order ID).
This creates a bracket order relationship where this conditional order activates after the specified parent order reaches a fill threshold.
Note: Cannot be used with order_linked_activation_client_id().
§Arguments
order_id- Exchange-assigned ID of the parent orderfill_quantity- Minimum fill quantity to activate (decimal string)
§Example
use types::api::submit_order::ConditionalBuilder;
let builder = ConditionalBuilder::new()
.order_linked_activation_order_id(123456789, "1.0");pub fn oco_link_client_id<S>(self, client_order_id: S) -> ConditionalBuilder
pub fn oco_link_client_id<S>(self, client_order_id: S) -> ConditionalBuilder
Links this order with another in an OCO (One-Cancels-Other) relationship.
Not supported. A conditional carrying an OCO link is rejected by the
sequencer with OcoOrdersNotSupported (129); nothing cancels the other
leg. Submit the two legs independently and cancel the loser yourself.
Note: Cannot be used with oco_link_order_id().
§Arguments
client_order_id- Client-assigned ID of the linked OCO order
§Example
use types::api::submit_order::ConditionalBuilder;
let builder = ConditionalBuilder::new()
.oco_link_client_id("stop-loss-order-456");pub fn oco_link_order_id(self, order_id: u128) -> ConditionalBuilder
pub fn oco_link_order_id(self, order_id: u128) -> ConditionalBuilder
Links this order with another in an OCO relationship (by order ID).
Not supported. A conditional carrying an OCO link is rejected by the
sequencer with OcoOrdersNotSupported (129).
Note: Cannot be used with oco_link_client_id().
§Arguments
order_id- Exchange-assigned ID of the linked OCO order
§Example
use types::api::submit_order::ConditionalBuilder;
let builder = ConditionalBuilder::new()
.oco_link_order_id(987654321);pub fn build(self) -> Result<Conditional, ConditionalBuilderError>
pub fn build(self) -> Result<Conditional, ConditionalBuilderError>
Builds the Conditional order, consuming the builder.
§Returns
Ok(Conditional)- Successfully built conditional orderErr(ConditionalBuilderError)- Missing required fields or invalid configuration
§Errors
Returns an error if:
- Any required field is missing (trigger_condition, trigger, reference_price)
- Order linking is used without fill quantity
- Both OCO client ID and order ID are specified
- Both activation client ID and order ID are specified
§Example
use types::api::submit_order::{ConditionalBuilder, Trigger};
let conditional = ConditionalBuilder::new()
.falls_below()
.trigger(Trigger::price("45000.00"))
.last_trade_price()
.build()
.expect("Failed to build conditional");Trait Implementations§
§impl Debug for ConditionalBuilder
impl Debug for ConditionalBuilder
§impl Default for ConditionalBuilder
impl Default for ConditionalBuilder
§fn default() -> ConditionalBuilder
fn default() -> ConditionalBuilder
Auto Trait Implementations§
impl Freeze for ConditionalBuilder
impl RefUnwindSafe for ConditionalBuilder
impl Send for ConditionalBuilder
impl Sync for ConditionalBuilder
impl Unpin for ConditionalBuilder
impl UnsafeUnpin for ConditionalBuilder
impl UnwindSafe for ConditionalBuilder
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
U: Sized,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
U: Sized,
self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read more§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> InitializableFromZeroed for Twhere
T: Default,
impl<T> InitializableFromZeroed for Twhere
T: Default,
§unsafe fn initialize(place: *mut T)
unsafe fn initialize(place: *mut T)
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].impl<T> MaybeSend for Twhere
T: Send,
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.