OrderRequestBuilder

Struct OrderRequestBuilder 

Source
pub struct OrderRequestBuilder<Symbol, Side, Type, Amt> { /* private fields */ }
Expand description

Builder for OrderRequest with typestate pattern for required fields.

The typestate pattern ensures at compile-time that all required fields (symbol, side, order_type, amount) are set before the build() method becomes available.

§Type Parameters

  • Symbol - Either Missing or Set<String> for the symbol field
  • Side - Either Missing or Set<OrderSide> for the side field
  • Type - Either Missing or Set<OrderType> for the order_type field
  • Amt - Either Missing or Set<Amount> for the amount field

§Examples

use ccxt_core::types::order_request::OrderRequestBuilder;
use ccxt_core::types::{OrderSide, OrderType, TimeInForce};
use ccxt_core::types::financial::{Amount, Price};
use rust_decimal_macros::dec;

// This compiles - all required fields are set
let request = OrderRequestBuilder::new()
    .symbol("BTC/USDT")
    .side(OrderSide::Buy)
    .order_type(OrderType::Limit)
    .amount(Amount::new(dec!(0.1)))
    .price(Price::new(dec!(50000)))
    .time_in_force(TimeInForce::GTC)
    .build();

Implementations§

Source§

impl OrderRequestBuilder<Missing, Missing, Missing, Missing>

Source

pub fn new() -> OrderRequestBuilder<Missing, Missing, Missing, Missing>

Creates a new OrderRequestBuilder with all required fields unset.

Source§

impl<Side, Type, Amt> OrderRequestBuilder<Missing, Side, Type, Amt>

Source

pub fn symbol( self, symbol: impl Into<String>, ) -> OrderRequestBuilder<Set<String>, Side, Type, Amt>

Sets the trading symbol (required).

§Arguments
  • symbol - Trading pair symbol (e.g., “BTC/USDT”)
Source§

impl<Symbol, Type, Amt> OrderRequestBuilder<Symbol, Missing, Type, Amt>

Source

pub fn side( self, side: OrderSide, ) -> OrderRequestBuilder<Symbol, Set<OrderSide>, Type, Amt>

Sets the order side (required).

§Arguments
  • side - Order side (Buy or Sell)
Source§

impl<Symbol, Side, Amt> OrderRequestBuilder<Symbol, Side, Missing, Amt>

Source

pub fn order_type( self, order_type: OrderType, ) -> OrderRequestBuilder<Symbol, Side, Set<OrderType>, Amt>

Sets the order type (required).

§Arguments
  • order_type - Order type (Market, Limit, etc.)
Source§

impl<Symbol, Side, Type> OrderRequestBuilder<Symbol, Side, Type, Missing>

Source

pub fn amount( self, amount: Amount, ) -> OrderRequestBuilder<Symbol, Side, Type, Set<Amount>>

Sets the order amount (required).

§Arguments
  • amount - Order quantity
Source§

impl<Symbol, Side, Type, Amt> OrderRequestBuilder<Symbol, Side, Type, Amt>

Source

pub fn price(self, price: Price) -> OrderRequestBuilder<Symbol, Side, Type, Amt>

Sets the order price (optional, required for limit orders).

§Arguments
  • price - Order price
Source

pub fn stop_price( self, stop_price: Price, ) -> OrderRequestBuilder<Symbol, Side, Type, Amt>

Sets the stop price (optional, for stop orders).

§Arguments
  • stop_price - Stop trigger price
Source

pub fn time_in_force( self, tif: TimeInForce, ) -> OrderRequestBuilder<Symbol, Side, Type, Amt>

Sets the time in force (optional).

§Arguments
  • tif - Time in force (GTC, IOC, FOK, PO)
Source

pub fn client_order_id( self, id: impl Into<String>, ) -> OrderRequestBuilder<Symbol, Side, Type, Amt>

Sets the client order ID (optional).

§Arguments
  • id - Client-specified order identifier
Source

pub fn reduce_only( self, reduce_only: bool, ) -> OrderRequestBuilder<Symbol, Side, Type, Amt>

Sets the reduce-only flag (optional, for futures).

When true, the order will only reduce an existing position.

Source

pub fn post_only( self, post_only: bool, ) -> OrderRequestBuilder<Symbol, Side, Type, Amt>

Sets the post-only flag (optional).

When true, the order will only be placed if it would be a maker order.

Source

pub fn trigger_price( self, trigger_price: Price, ) -> OrderRequestBuilder<Symbol, Side, Type, Amt>

Sets the trigger price (optional, for conditional orders).

§Arguments
  • trigger_price - Price at which the order is triggered
Source

pub fn take_profit_price( self, take_profit_price: Price, ) -> OrderRequestBuilder<Symbol, Side, Type, Amt>

Sets the take profit price (optional).

§Arguments
  • take_profit_price - Take profit trigger price
Source

pub fn stop_loss_price( self, stop_loss_price: Price, ) -> OrderRequestBuilder<Symbol, Side, Type, Amt>

Sets the stop loss price (optional).

§Arguments
  • stop_loss_price - Stop loss trigger price
Source

pub fn trailing_delta( self, delta: Decimal, ) -> OrderRequestBuilder<Symbol, Side, Type, Amt>

Sets the trailing delta in basis points (optional).

§Arguments
  • delta - Trailing delta in basis points
Source

pub fn trailing_percent( self, percent: Decimal, ) -> OrderRequestBuilder<Symbol, Side, Type, Amt>

Sets the trailing percent (optional).

§Arguments
  • percent - Trailing percentage
Source

pub fn activation_price( self, activation_price: Price, ) -> OrderRequestBuilder<Symbol, Side, Type, Amt>

Sets the activation price (optional, for trailing stop orders).

§Arguments
  • activation_price - Price at which trailing stop activates
Source

pub fn callback_rate( self, rate: Decimal, ) -> OrderRequestBuilder<Symbol, Side, Type, Amt>

Sets the callback rate (optional, for futures trailing stop orders).

§Arguments
  • rate - Callback rate percentage
Source

pub fn working_type( self, working_type: impl Into<String>, ) -> OrderRequestBuilder<Symbol, Side, Type, Amt>

Sets the working type (optional, for futures).

§Arguments
  • working_type - “CONTRACT_PRICE” or “MARK_PRICE”
Source

pub fn position_side( self, position_side: impl Into<String>, ) -> OrderRequestBuilder<Symbol, Side, Type, Amt>

Sets the position side (optional, for hedge mode futures).

§Arguments
  • position_side - “LONG”, “SHORT”, or “BOTH”
Source§

impl OrderRequestBuilder<Set<String>, Set<OrderSide>, Set<OrderType>, Set<Amount>>

Source

pub fn build(self) -> OrderRequest

Builds the final OrderRequest.

This method is only available when all required fields (symbol, side, order_type, amount) have been set.

§Returns

A fully constructed OrderRequest with all specified fields.

§Examples
use ccxt_core::types::order_request::OrderRequest;
use ccxt_core::types::{OrderSide, OrderType};
use ccxt_core::types::financial::Amount;
use rust_decimal_macros::dec;

let request = OrderRequest::builder()
    .symbol("BTC/USDT")
    .side(OrderSide::Buy)
    .order_type(OrderType::Market)
    .amount(Amount::new(dec!(0.1)))
    .build();

assert_eq!(request.symbol, "BTC/USDT");

Trait Implementations§

Source§

impl<Symbol, Side, Type, Amt> Clone for OrderRequestBuilder<Symbol, Side, Type, Amt>
where Symbol: Clone, Side: Clone, Type: Clone, Amt: Clone,

Source§

fn clone(&self) -> OrderRequestBuilder<Symbol, Side, Type, Amt>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Symbol, Side, Type, Amt> Debug for OrderRequestBuilder<Symbol, Side, Type, Amt>
where Symbol: Debug, Side: Debug, Type: Debug, Amt: Debug,

Source§

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

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

impl Default for OrderRequestBuilder<Missing, Missing, Missing, Missing>

Source§

fn default() -> OrderRequestBuilder<Missing, Missing, Missing, Missing>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<Symbol, Side, Type, Amt> Freeze for OrderRequestBuilder<Symbol, Side, Type, Amt>
where Symbol: Freeze, Side: Freeze, Type: Freeze, Amt: Freeze,

§

impl<Symbol, Side, Type, Amt> RefUnwindSafe for OrderRequestBuilder<Symbol, Side, Type, Amt>
where Symbol: RefUnwindSafe, Side: RefUnwindSafe, Type: RefUnwindSafe, Amt: RefUnwindSafe,

§

impl<Symbol, Side, Type, Amt> Send for OrderRequestBuilder<Symbol, Side, Type, Amt>
where Symbol: Send, Side: Send, Type: Send, Amt: Send,

§

impl<Symbol, Side, Type, Amt> Sync for OrderRequestBuilder<Symbol, Side, Type, Amt>
where Symbol: Sync, Side: Sync, Type: Sync, Amt: Sync,

§

impl<Symbol, Side, Type, Amt> Unpin for OrderRequestBuilder<Symbol, Side, Type, Amt>
where Symbol: Unpin, Side: Unpin, Type: Unpin, Amt: Unpin,

§

impl<Symbol, Side, Type, Amt> UnwindSafe for OrderRequestBuilder<Symbol, Side, Type, Amt>
where Symbol: UnwindSafe, Side: UnwindSafe, Type: UnwindSafe, Amt: UnwindSafe,

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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