Skip to main content

OrderFactory

Struct OrderFactory 

Source
pub struct OrderFactory { /* private fields */ }

Implementations§

Source§

impl OrderFactory

Source

pub fn new( trader_id: TraderId, strategy_id: StrategyId, init_order_id_count: Option<usize>, init_order_list_id_count: Option<usize>, clock: Rc<RefCell<dyn Clock>>, use_uuids_for_client_order_ids: bool, use_hyphens_in_client_order_ids: bool, ) -> Self

Creates a new OrderFactory instance.

Source

pub const fn set_client_order_id_count(&mut self, count: usize)

Sets the client order ID generator count.

Source

pub const fn client_order_id_count(&self) -> usize

Returns the client order ID generator count.

Source

pub const fn set_order_list_id_count(&mut self, count: usize)

Sets the order list ID generator count.

Source

pub const fn order_list_id_count(&self) -> usize

Returns the order list ID generator count.

Source

pub fn generate_client_order_id(&mut self) -> ClientOrderId

Generates a new client order ID.

Source

pub fn generate_order_list_id(&mut self) -> OrderListId

Generates a new order list ID.

Source

pub const fn reset_factory(&mut self)

Resets the factory by resetting all ID generators.

Source

pub fn market( &mut self, instrument_id: InstrumentId, order_side: OrderSide, quantity: Quantity, time_in_force: Option<TimeInForce>, reduce_only: Option<bool>, quote_quantity: Option<bool>, exec_algorithm_id: Option<ExecAlgorithmId>, exec_algorithm_params: Option<IndexMap<Ustr, Ustr>>, tags: Option<Vec<Ustr>>, client_order_id: Option<ClientOrderId>, ) -> OrderAny

Creates a new market order.

§Panics

Panics if the order parameters fail validation.

Source

pub fn limit( &mut self, instrument_id: InstrumentId, order_side: OrderSide, quantity: Quantity, price: Price, time_in_force: Option<TimeInForce>, expire_time: Option<UnixNanos>, post_only: Option<bool>, reduce_only: Option<bool>, quote_quantity: Option<bool>, display_qty: Option<Quantity>, emulation_trigger: Option<TriggerType>, trigger_instrument_id: Option<InstrumentId>, exec_algorithm_id: Option<ExecAlgorithmId>, exec_algorithm_params: Option<IndexMap<Ustr, Ustr>>, tags: Option<Vec<Ustr>>, client_order_id: Option<ClientOrderId>, ) -> OrderAny

Creates a new limit order.

§Panics

Panics if the order parameters fail validation.

Source

pub fn stop_market( &mut self, instrument_id: InstrumentId, order_side: OrderSide, quantity: Quantity, trigger_price: Price, trigger_type: Option<TriggerType>, time_in_force: Option<TimeInForce>, expire_time: Option<UnixNanos>, reduce_only: Option<bool>, quote_quantity: Option<bool>, display_qty: Option<Quantity>, emulation_trigger: Option<TriggerType>, trigger_instrument_id: Option<InstrumentId>, exec_algorithm_id: Option<ExecAlgorithmId>, exec_algorithm_params: Option<IndexMap<Ustr, Ustr>>, tags: Option<Vec<Ustr>>, client_order_id: Option<ClientOrderId>, ) -> OrderAny

Creates a new stop-market order.

§Panics

Panics if the order parameters fail validation.

Source

pub fn stop_limit( &mut self, instrument_id: InstrumentId, order_side: OrderSide, quantity: Quantity, price: Price, trigger_price: Price, trigger_type: Option<TriggerType>, time_in_force: Option<TimeInForce>, expire_time: Option<UnixNanos>, post_only: Option<bool>, reduce_only: Option<bool>, quote_quantity: Option<bool>, display_qty: Option<Quantity>, emulation_trigger: Option<TriggerType>, trigger_instrument_id: Option<InstrumentId>, exec_algorithm_id: Option<ExecAlgorithmId>, exec_algorithm_params: Option<IndexMap<Ustr, Ustr>>, tags: Option<Vec<Ustr>>, client_order_id: Option<ClientOrderId>, ) -> OrderAny

Creates a new stop-limit order.

§Panics

Panics if the order parameters fail validation.

Source

pub fn market_to_limit( &mut self, instrument_id: InstrumentId, order_side: OrderSide, quantity: Quantity, time_in_force: Option<TimeInForce>, expire_time: Option<UnixNanos>, reduce_only: Option<bool>, quote_quantity: Option<bool>, display_qty: Option<Quantity>, exec_algorithm_id: Option<ExecAlgorithmId>, exec_algorithm_params: Option<IndexMap<Ustr, Ustr>>, tags: Option<Vec<Ustr>>, client_order_id: Option<ClientOrderId>, ) -> OrderAny

Creates a new market-to-limit order.

§Panics

Panics if the order parameters fail validation.

Source

pub fn market_if_touched( &mut self, instrument_id: InstrumentId, order_side: OrderSide, quantity: Quantity, trigger_price: Price, trigger_type: Option<TriggerType>, time_in_force: Option<TimeInForce>, expire_time: Option<UnixNanos>, reduce_only: Option<bool>, quote_quantity: Option<bool>, emulation_trigger: Option<TriggerType>, trigger_instrument_id: Option<InstrumentId>, exec_algorithm_id: Option<ExecAlgorithmId>, exec_algorithm_params: Option<IndexMap<Ustr, Ustr>>, tags: Option<Vec<Ustr>>, client_order_id: Option<ClientOrderId>, ) -> OrderAny

Creates a new market-if-touched order.

§Panics

Panics if the order parameters fail validation.

Source

pub fn limit_if_touched( &mut self, instrument_id: InstrumentId, order_side: OrderSide, quantity: Quantity, price: Price, trigger_price: Price, trigger_type: Option<TriggerType>, time_in_force: Option<TimeInForce>, expire_time: Option<UnixNanos>, post_only: Option<bool>, reduce_only: Option<bool>, quote_quantity: Option<bool>, display_qty: Option<Quantity>, emulation_trigger: Option<TriggerType>, trigger_instrument_id: Option<InstrumentId>, exec_algorithm_id: Option<ExecAlgorithmId>, exec_algorithm_params: Option<IndexMap<Ustr, Ustr>>, tags: Option<Vec<Ustr>>, client_order_id: Option<ClientOrderId>, ) -> OrderAny

Creates a new limit-if-touched order.

§Panics

Panics if the order parameters fail validation.

Source

pub fn trailing_stop_market( &mut self, instrument_id: InstrumentId, order_side: OrderSide, quantity: Quantity, trailing_offset: Decimal, trailing_offset_type: Option<TrailingOffsetType>, activation_price: Option<Price>, trigger_price: Option<Price>, trigger_type: Option<TriggerType>, time_in_force: Option<TimeInForce>, expire_time: Option<UnixNanos>, reduce_only: Option<bool>, quote_quantity: Option<bool>, display_qty: Option<Quantity>, emulation_trigger: Option<TriggerType>, trigger_instrument_id: Option<InstrumentId>, exec_algorithm_id: Option<ExecAlgorithmId>, exec_algorithm_params: Option<IndexMap<Ustr, Ustr>>, tags: Option<Vec<Ustr>>, client_order_id: Option<ClientOrderId>, ) -> OrderAny

Creates a new trailing-stop-market order.

§Panics

If neither trigger_price nor activation_price is provided.

Source

pub fn trailing_stop_limit( &mut self, instrument_id: InstrumentId, order_side: OrderSide, quantity: Quantity, price: Price, limit_offset: Decimal, trailing_offset: Decimal, trailing_offset_type: Option<TrailingOffsetType>, activation_price: Option<Price>, trigger_price: Option<Price>, trigger_type: Option<TriggerType>, time_in_force: Option<TimeInForce>, expire_time: Option<UnixNanos>, post_only: Option<bool>, reduce_only: Option<bool>, quote_quantity: Option<bool>, display_qty: Option<Quantity>, emulation_trigger: Option<TriggerType>, trigger_instrument_id: Option<InstrumentId>, exec_algorithm_id: Option<ExecAlgorithmId>, exec_algorithm_params: Option<IndexMap<Ustr, Ustr>>, tags: Option<Vec<Ustr>>, client_order_id: Option<ClientOrderId>, ) -> OrderAny

Creates a new trailing-stop-limit order.

§Panics

If neither trigger_price nor activation_price is provided.

Source

pub fn create_list( &mut self, orders: &mut [OrderAny], ts_init: UnixNanos, ) -> OrderList

Creates a new [OrderList] from the given orders, generating a fresh order list ID and propagating it back to each order.

All orders must share the same venue; the caller is responsible for passing orders with the factory’s strategy_id. The returned list’s invariants are checked by [OrderList::validate] at submission time.

§Panics

Panics if orders is empty or if orders span more than one venue. Callers are expected to guard non-empty input; Strategy::submit_order_list filters out the empty case and bails on mixed venues before reaching this constructor.

Source

pub fn bracket<'f1>(&'f1 mut self) -> OrderFactoryBracketBuilder<'f1>

Creates a bracket order with an entry order and attached take-profit and stop-loss legs.

Defaults:

  • contingency_type: Ouo for the TP/SL legs.
  • entry_order_type: Market; tp_order_type: Limit; sl_order_type: StopMarket.
  • entry_tags: ["ENTRY"]; tp_tags: ["TAKE_PROFIT"]; sl_tags: ["STOP_LOSS"].
  • tp_post_only: true for Limit and LimitIfTouched; entry_post_only: false.
  • TP and SL legs are always reduce_only = true; the entry is reduce_only = false.
  • TP and SL legs do not inherit expire_time from the entry.
§Panics

Panics if entry_order_type, tp_order_type, or sl_order_type is not one of the supported variants, or if a required price/trigger field is missing for the chosen type.

Trait Implementations§

Source§

impl Debug for OrderFactory

Source§

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

Formats the value using the given formatter. Read more

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more